Hi,
On 13 Okt., 08:56, Laurent PETIT <[email protected]> wrote:
> So in short: calling eval from the macro, on its argument.
Beware the leopard!
user=> (defn f
[constant]
`(+ x# (* ~constant y#)))
#'user/f
user=> (defn variables*
[form]
(if (seq? form)
(reduce into [] (map variables* form))
(when (and (symbol? form) (nil? (resolve form)))
[form])))
#'user/variables*
user=> (defmacro variables
[form]
`(variables* (quote ~form)))
#'user/variables
user=> (defmacro dynamic?-variables
[form]
`(variables ~(eval form)))
#user/dynamic?-variables
user=> (dynamic?-variables '(+ x (* 2 y)))
[x y]
user=> (dynamic?-variables (+ x (* 2 y)))
java.lang.Exception: Unable to resolve symbol: x in this context
(NO_SOURCE_FILE:18)
user=> (dynamic?-variables (f 2))
[x__12__auto__ y__13__auto__]
user=> (let [x 2] (dynamic?-variables (f x)))
java.lang.InstantiationException: user$eval48$eval49__50
(NO_SOURCE_FILE:52)
One has to be aware of the limitations of such an approach.
Sincerely
Meikel
--
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