On Mar 10, 12:48 pm, stu <[email protected]> wrote:
> Hi,
>
> This is a newb question so apologies in advance if I haven't read
> enough Clojure code yet to see the answer.
>
> Suppose I need mathematical 2D vector functions:
>
> (ns geometry.vector)
>
> (defstruct vector :x :y)
>
> (defn +
> "Add vectors v and w, yielding a vector"
> [ v w ]
> (...))
>
> Which leads to the core "vector" function being shadowed by my struct
> and the core "+" function shadowed by my function. What is the
> idiomatic Clojure approach for handling this situation? Is it through
> careful use of :require and :import parts of a (ns ...) form?
>
> I've also seen instances of naming changes to avoid the problem, e.g.
> (defstruct <vector> ...) and (defn vector+ ...)
> but not sure if that's making best use of Clojure namespaces?
>
> Any advice much appreciated,
>
> Stu
user=> (ns math (:refer-clojure :rename {vector cvector}))
nil
math=> vector
java.lang.Exception: Unable to resolve symbol: vector in this context
(NO_SOURCE_FILE:0)
math=> (def vector identity)
#'math/vector
math=> (vector 10)
10
math=> (cvector 10)
[10]
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en