Hi,
In my recent macro-writing adventure, I discovered that (gensym) is
not actually equivalent to using #.
Can someone explain to me how # actually works in backquoted form?

eg. This doesn't work:
(defmacro deftemp [name text]
  `(do (def temp# ~text)
       (defn ~name [] temp#)))

In repl:
(deftemp temp1 "temp1")
(deftemp temp2 "temp2")

(temp1) returns "temp2" <= incorrect.

BUT this does work:
(defmacro deftemp [name text]
  (let [temp (gensym "temp")]
    `(do (def ~temp ~text)
         (defn ~name [] ~temp))))

In Repl:
(deftemp temp1 "temp1")
(deftemp temp2 "temp2")

(temp1) correct returns "temp1" <= correct.

I originally thought that # uses (gensym) internally. But it seems
that's not the case?
Thanks for your help
  -Patrick
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to