On 20/06/13 08:49, Phillip Lord wrote:
Well, that doesn't answer the question. The backtick is useful in
writing macros (although the situation this caused me grief, actually, I
wasn't). So is quote. But then I do not understand why the behaviour is
different between the two.
I thought the question was whether this is expected or not that's why I
answered accordingly...What I wanted to get across is that ` is critical
for generating code (macro-writing) whereas ' has nothing to do with
macros really. It's just a way of saying 'skip evaluation of this symbol
- just pass it along'. However, whenever you do `(map ~f ~coll) what you
really mean is (clojure.core/map some-fn some-coll) and that is exactly
what the macro will expand to. Say, you had overwritten 'core.map' with
your own version in that namespace...then the macro would expand to
(some-namespace/map some-fn some-coll) . If you swap ` for ' then what
you get is a list with a bunch of non-qualified symbols in. Not very
useful is it?
Ambrose went a bit further and explained local-name capturing & gensym.
Even though automatic namespace qualification helps with that, it seems
to be that this is not the primary reason for it. Being able to generate
code dynamically without having to qualify every single symbol sounds
more important to me...after all, avoiding local name capturing can be
considered the programmer's responsibility...ok, the language helps with
gensym etc but it should always be in the back of your head when writing
macros. Even with gensym and syntax-quote there is still a way to
achieve name capturing and I think 'the joy of Clojure' demonstrates an
'arguably useful' example of this...
to sum up the behaviour is different because ` & ' are used to achieve
different tasks. It often helps me to think of ` as resolving the symbol
whereas ' doesn't do anything to it.
hope this is clearer now...
this is nice video http://www.infoq.com/presentations/Clojure-Macros
that explains the compilation process of Clojure and how macros make it
harder to grasp.
Jim
--
--
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
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.