On 3 Jun 2010, at 12:46, alux wrote:

Thats impressive. I'm still, hm, puzzled. Nice example of something
that can only be done with syntax-quote, and outside of a macro. (Or
can this be done without syntax-quote, and I just dont see it?)

That particular example is easy to do without syntax-quote:

        (map (fn [s v]  (list 'def s v)) '(a b c) '(1 2 3))

Syntax-quote shows its stregths for nested forms, which would be a pain to construct step by step using list and cons - but it's always possible.

Is there any predicate like (macro? my-macro), and, if we are at it
(special-form? my-form) ?

user> (defmacro macro? [x] `(get  (meta  (var ~x)) :macro false ))
#'user/macro?
user> (macro? and)
true
user> (macro? map)
false

user> (special-symbol? 'def)
true
user> (special-symbol? 'map)
false

Note that macro? must be defined as a macro because otherwise its argument would be evaluated, which is not possible for a macro. special-symbol? is built-in, it works by interrogating the compiler's internal list of special forms.

We could even generalise map with the thing you just described!(?)

It's not more general, it's different!

One more thing. I'm still heavily irritated about the expansion of
'`(foo (bar ~a) ~b)

From clojure.org/reader, I learned "For Lists/Vectors/Sets/Maps,
syntax-quote establishes a template of the corresponding data
structure.", and from that, what I expected was
(user/foo (user/bar a) b)

Why is this so utterly wrong, and where should I know?

Your expression would first call user/bar with argument a, and then feed that and b as arguments to a call to user/foo. But you don't want to call the functions, you want to return a form that calls them when passed to eval. Here is what you would come up with when doing the equivalent of `(foo (bar ~a) ~b) by hand:

        (list 'user/foo (list 'user/bar a) b)

What Clojure returns is equivalent, but more complicated because it has to work with more complex input as well.

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

Reply via email to