While trying to understand the doubly indented lines in the following
definition from "Programming Clojure" by Stuart Halloway:

(defmacro deftarget [sym doc & forms]
  (let [has-run-fn (gensym "hr-" ) reset-fn (gensym "rf-" )]
  `(let [[~has-run-fn ~reset-fn once-fn#] (runonce (fn [] ~...@forms))]
  (def
    ~(with-meta
    sym
    {:doc doc :has-run-fn has-run-fn :reset-fn reset-fn})
  once-fn#))))

I made the following confusing discovery:

#^ works as expected:
user=> (def #^{:doc "say bah 2 times"} bah2 #(println "bah bah"))
#'user/bah2
user=> (bah2)
bah bah
nil
user=> ^#'bah2
{:ns #<Namespace user>, :name bah2, :file "NO_SOURCE_FILE", :line 5,
:doc "say bah 2 times"}

But with-meta does not:
user=> (def (with-meta 'bah3 {:doc "say bah 3 times"}) #(println "bah
bah bah"))
java.lang.Exception: Second argument to def must be a Symbol
(NO_SOURCE_FILE:12)

although with-meta returns a symbol:
user=> (class (with-meta 'bah3 {:doc "say bah 3 times"}))
clojure.lang.Symbol

which has the expected metadata:
user=> (meta (with-meta 'bah3 {:doc "say bah 3 times"}))
{:doc "say bah 3 times"}

Am I not understanding something or is there a bug here?

Thanks
gun43

--~--~---------~--~----~------------~-------~--~----~
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