I am playing around with a macro to define accessor functions for a closed-over atom. Here is a simplified example:
(defmacro hidden-atom [] (let [a (atom :hello)] `(defn get-value [] (deref ~a)))) When I evaluate this macro, I get the error: "Can't embed object in code, maybe print-dup not defined: clojure.lang.a...@1a7693a" I imagined this should work, as the above macro doesn't seem too different from the following macro, which does work: (defmacro hidden-function[] (let [a (fn [] :hello)] `(defn get-value [] (~a)))) When using macroexpand-1, both macros return nearly identical forms: gdsl.proc> (macroexpand '(hidden-atom)) (def gdsl.proc/get-value (.withMeta (clojure.core/fn gdsl.proc/get- value ([] (clojure.core/deref #<a...@10a5e22: :hello>))) (.meta (var gdsl.proc/get-value)))) gdsl.proc> (macroexpand '(hidden-function)) (def gdsl.proc/get-value (.withMeta (clojure.core/fn gdsl.proc/get- value ([] (#<proc$hidden_function$a__15149 gdsl.proc$hidden_function $a__15...@bde2da>))) (.meta (var gdsl.proc/get-value)))) I'm afraid I don't know enough about macro expansion to understand what is wrong here. -- 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