Hi Razvan,
Can you tell us a bit more:
(1) the stack trace of the error you are seeing
(2) the form you are using to call order-query
(3) what you expect evaling something at macroexpansion time should be doing
Thanks,
Stu
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
One case where there is not enough information -- and a minimal "Can't
eval locals" example -- is the following:
(defmacro foo [x] (eval x))
(let [y 1] (foo y))
Are you doing something similar...?
eval's behaviour here is very sensible, since it is asked to eval the
Symbol y at compile time, when it knows that it names a local binding,
but does not know what the value of that local binding is going to be
at runtime. (It could conceivably notice that this particular local is
given a constant initializer expression, but that would only raise
expectations for cases like (let [y (some-function)] (foo y)) where
using the compile-time return value of (some-function) would make no
sense even if it were possible to obtain it.)
That doesn't mean eval'ing stuff at compile time is not possible, it's
just that one has to make sure that one is eval'ing forms which have
meaningful compile-time values.
Sincerely,
Michał
PS. Actually it's fun to go code diving to see how this breaks
exactly... Although it's not terribly helpful in writing code. A
summary of the code path this goes through is, I think, that
clojure.core/eval delegates to clojure.lang.Compiler.eval, which in
turn needs the expression analysed by clojure.lang.Compiler.analyze,
which in this case delegates to clojure.lang.Compiler.analyzeSymbol,
which in this case -- called at compile-time inside this particular
let form -- finds a binding for the Symbol y included in the local
environment and accordingly returns a LocalBindingExpr, which is
something un-eval-able.
Anyway, I think Joop's answer (especially the first code snippet) is
*very* likely to be the best. As far as I can tell from reading the
source, appengine-magic's query macro includes the filter expression
in its expansion verbatim, so it will just be evaluated at run time.
If you do want to play around with some super-flexible eval-based
approaches, you might want to give Michael Fogus's highly enjoyable
evalive library [1] a try -- it provides an aptly named #'evil
function which, together with its companion macro #'local-bindings (or
was it #'local-env...), does allow one more flexibility in what one
evals. The usual warnings (don't eval unless you have to etc.) apply.
Sincerely,
Michał