Thank you, this has been very helpfull. The reason I came across this problem is that I never intended to evaluate the symbols in the expression trees. I rather wanted to use them to represent symbolic constants in an abstract expression tree. I am now convinced that using keywords throughout is the better approach.
Thanks, Felix On 12 Mrz., 15:01, Konrad Hinsen <konrad.hin...@fastmail.net> wrote: > On 12.03.2010, at 10:32, Felix Breuer wrote: > > > I guess I have to rephrase my previous questions to make them more > > clear: Why was this particular behavior chosen? What is the benefit of > > having quote and syntax-quote behaving differently in this regard? > > Quote and syntax-quote serve very different purposes, despite the similar > name an a superficial resemblance in functionality. > > Quote is for writing unevaluated literals. You just want nothing changed in > its argument, which is exactly what it does. > > Syntax-quote is used for writing code templates, mostly inside macro > definitions. In that situation, you want symbols be resolved in namespaces, > just as they would if the form being constructed were used literally in the > same place. To make code templates work correctly across namespaces > (typically a macro is expanded in another namespace than the one it was > defined in), it is thus preferable to have symbols converted to their > namespace-qualified counterparts. > > You might want to look at this blog post, whose topic is an exceptional > situation where syntax-quote is not the most convenient way to write code > templates: > > http://onclojure.com/2010/02/23/generating-deftype-forms-in-macros/ > > > Suppose I wanted to write my own version of = called (myeql a b) such > > that > > > user> (myeql '(v 1) `(v 1)) > > true > > > I would have to walk the expression tree in both expressions and > > replace all unqualified symbols with the respective qualified symbols. > > How would I go about this? Is there an idomatic way to achieve this? > > I don't see why you would ever want to do this, but here is one approach (not > idiomatic): > - use clojure.walk to apply a transformation all over a form > - for each leaf of the tree, check if it is a symbol and if so, convert it to > its namespace-qualified equivalent. > > What is rather strange in my opinion is the fact that there is no utility > function in clojure. core that does the second step, i.e. there is no > function that will map 'x to `x. However, it is not difficult to write such a > function: > > (defn qualified-symbol > [s] > (symbol (str *ns*) (str s))) > > Konrad. -- 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