After a fair amount of macro writing in CL, I think I got the
backquote expansion mechanism pretty much nailed down (after all, it
is quite clear in the HyperSpec). Now, I thought I understood the
Clojure algorithm just as well. It looked very similar (concat instead
of append and so on). Apart from the namespace resolution business,
and a few other irrelevant details, the essence looked the same.

But I did the following just for fun, and I got a surprising result:

> (def x `a)
> (def a 5)
> `(list `(list ,,x))

What I theoretically was expecting was the outcome of this:

(concat (list `list) (list (concat (list `concat) (list (concat (list
`list) (list ``list))) (list (concat (list `list) (list x))))))

In other words, behind the curtains, the latter was supposed to be
evaluated. Now, as Guy Steele points out, with a k-level nested
backquote, you are guaranteed to get the same result only after k
evaluations. So evaluating twice the result is:

((clojure.core/list 5))

I checked this in Common Lisp and the result was sure enough exactly
the equivalent, as I expected.

Yet, in clojure this is what happens (of course you see the first
evaluation directly in this case):

> `(list `(list ,,x))
(clojure.core/list (clojure.core/concat (clojure.core/list (quote
clojure.core/list)) (clojure.core/list (quote user/x))))

Another evaluation gives:
((clojure.core/list user/x))

That's ALMOST the same but not quite. See the "user/x"? It came from a
very strange (quote user/x) above which wasn't supposed to be there. I
mean user/x should not have been quoted.

Is this a bug?

Rock

--~--~---------~--~----~------------~-------~--~----~
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
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