Created
April 19, 2011 15:48
-
-
Save MrGung/928553 to your computer and use it in GitHub Desktop.
Clojure macros don't work with complex objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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