On Jan 6, 11:35 pm, wubbie <sunj...@gmail.com> wrote:
> Hi,
> Here is the question on differences between with-meta and #^
> Specifically 1) and 2) are different in that 1) has meta info carried
> over
> to jumping-wubbie, while 2) has not.
> What's the rationale behind this?
>
> user=> (def wubbie {:name "Wubbie" :email "wub...@gmail.com"})
> #'user/wubbie
> user=> wubbie
> {:name "Wubbie", :email "wub...@gmail.com"}
> user=> ^wubbie
> nil
> user=> (def jumping-wubbie (with-meta wubbie {:jumping true})) ;; 1)
> meta info set
> #'user/jumping-wubbie
> user=> ^jumping-wubbie
> {:jumping true}
> user=> (def jumping-wubbie2 #^{:jumping true} wubbie) ;; 2) meta inof
> not carried over
> #'user/jumping-wubbie2
> user=> ^jumping-wubbie2
> nil
>
> Thanks
> Sun
Stu H. mentions this in his book.
The briefest way to explain it is with the following code:
user=> (= #^{:jumping true} {:name "Wubbie", :email
"wub...@mgail.com"} #^{:jumping true} wubbie)
false
In the case of "#^{metadata} symbol" you are adding the metadata to
the symbol, but then the symbol gets evaluated and it's *value* is
returned, not the metadata.
Maybe this makes it more clear?
user=> (meta #^{:jumping true} wubbie)
nil
I'm very much a Clojure n00b, but I would also expect the behavior you
were expecting. I wonder if this implementation of #^ was intended,
or if this was just an oversight? I think there is something lacking
in my fundamental knowledge of Clojure, and that's why this has yet to
make complete sense to me.
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---