Hello again,

This has solved the issue:

(let [cache (atom {})
      cache-eval (fn [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) (cache-eval fbody)))
  (defmacro eval-cached
        "Just as eval, however it will return an existing object if it has
already been evaluated with it"
        [obj]
        (cache-eval obj)))

However it'll be good if someone could share some insight why a macro
cannot call another one and what is the general solution in such a
case

Stanislav Paskalev



On Tue, May 3, 2011 at 3:50 PM, Stanislav Paskalev <ksh...@gmail.com> wrote:
> 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 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

Reply via email to