On Wed, Apr 10, 2013 at 2:13 PM, Jim foo.bar <jimpil1...@gmail.com> wrote:
> On 10/04/13 14:03, Simon Katz wrote: > >> Second, Clojure supports namespace-qualified keywords, presumably because >> it's possible that different libraries might want to use the same keyword >> for different purposes. >> > > I don't think that is the reason for having namespace-qualified > keywords...different libraries might want to use the same keyword for > different purposes and that is fine - no clashes (or at elast I've not > understood what you mean). > > It's my understanding that ::foo has (or should have) actual 'meaning' in > whatever namespace it exists whereas :foo doesn’t really have any 'meaning'. > Here's an example of what I mean. In the code below, a/foo and b/bar use unqualified keywords. At the line marked (1), which uses both those functions, you can see that the value set up by b/bar has been lost. Similarly, at (2) the value set up by a/foo has been lost. (1) and (2) illustrate what I mean by a clash. At (3), which uses functions that use namespace-qualified keywords, the result includes the values set up by both a/foo-nsq and b/bar-nsq — no clash. Hopefully that clarifies things. I don't think I'm trying to do anything unusual here. For example, *The Joy of Clojure* (pages 69-72) and *Clojure Programming* (page 14) both talk about using namespace-qualified symbols in this kind of way. user> (ns a) a> (defn foo [m] (assoc m :kw 1)) a> (defn foo-nsq [m] (assoc m ::kw 1)) a> (ns b) b> (defn bar [m] (assoc m :kw 2)) b> (defn bar-nsq [m] (assoc m ::kw 2)) b> (in-ns 'user) user> (a/foo (b/bar {})) ; (1) ;; => {:kw 1} user> (b/bar (a/foo {})) ; (2) ;; => {:kw 2} user> (a/foo-nsq (b/bar-nsq {})) ; (3) ;; => {:a/kw 1, :b/kw 2} It seems to me odd that Clojure recognises that namespace-qualified symbols are needed and yet that defrecord seems to not respect the fact. I don't really think you want to access your record fields with a > namespace-qualified keyword, do you? How would that work exactly? what if > you got an instance of the record outside the namespace where the > namespace-qualified keyword is defined? It doesn't make sense to me at > all... I don't understand this. (It's possible to use a namespace-qualified symbol from outside the namespace.) -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.