Hi,

Am 26.01.2009 um 18:15 schrieb gun43:

(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#))))

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

def is a special form. Its second argument doesn't get
evaluated. Hence def sees the (with-meta ..) itself, not
its value, the symbol. Hence you get the Exception.

In the macro this works, because the with-meta there
is evaluated before the resulting (def ..) form is passed
on to the compiler. So the def here really sees the symbol.

Hope this helps.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to