Skip to content

Instantly share code, notes, and snippets.

@MrGung
Created April 19, 2011 15:48
Show Gist options
  • Save MrGung/928553 to your computer and use it in GitHub Desktop.
Save MrGung/928553 to your computer and use it in GitHub Desktop.
Clojure macros don't work with complex objects
;; This will work as expected:
(defmacro create-task-with-out [& body]
(let [[code meta] (get-code-and-meta body)]
`(let [temp-file-out# (get meta :out-file-obj (create-temp-file))]
(Task. (future (wrap-with-out temp-file-out# ~@code))
(assoc ~meta :out-file (.getAbsolutePath temp-file-out#))))))
;; Whereas the following snippet won't work:
(defmacro create-task-with-out [& body]
(let [[code meta] (get-code-and-meta body)
temp-file-out (get meta :out-file-obj (create-temp-file))]
`(Task. (future (wrap-with-out ~temp-file-out ~@code))
(assoc ~meta :out-file (.getAbsolutePath ~temp-file-out)))))
(create-task-with-out (println "hello world") (println "you me too!")) fails with:
;; Giving the exception:
;; Can't embed object in code, maybe print-dup not defined: D:\DOKUME~1\Steffen\LOKALE~1\Temp\clj_1145300297477803280.tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment