Guofeng Zhang <[email protected]> writes:
> I do not understand why "`'~v" has be to used this way. If I used
> "`~v" instead (that is, remove the quote), it still works. So my
> question is, why "~v" needs to be first quoted and then syntax-quoted?
I'm not the most experienced Clojure programmer, but I'll have a go:
The key is to count the levels of quoting, and make sure they match what
you need at each level for each form. Using just `~ is (almost) a
no-op. Putting ' in between them yields the a form containing the
quoted *value* of v, which is equivalent to the (possibly clearer)
`(quote ~v). The quoting comes into play for symbols, because quoting
captures any symbols as literal symbol objects vs whatever they resolve
to in the lexical scope. If you pass {'a 'one} in for the ctx argument
to contextual-eval as-is, then the symbol `one' ends up quoted in the
generated let, and `a' properly bound to the symbol object. If you
modify the function to *not* quote the value, then an unquoted `one' get
inserted instead, and the function throws an error because `one' is
unbound.
HTH,
-Marshall
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en