Hello,
Evaluating the form
(let [cache (atom {})]
(defmacro eval-cached
"Just as eval, however it will return an existing object if it has
already been evaluated with it"
[obj]
(when-not (contains? @cache obj)
(reset! cache (assoc @cache obj (eval obj))))
(@cache obj))
(defmacro def-cached
"Just as def, however it will return an existing object if it has
already been defined with it"
[fname fbody]
(intern *ns* (symbol fname) (eval-cached fbody))))
Gives me a java.lang.UnsupportedOperationException: Can't eval locals
- for the last line of "def-cached"
However, when I use eval the first defmacro by itself as a closure -
it works perfectly. How can I make those share the cache state without
binding it to a public symbol ?
Best regards,
Stanislav Paskalev
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en