Hi,

I'm reading the second edition of Joy of Clojure (the MEAP), and there is 
an example that I don't quite get, and I was hoping someone here could help 
me. It's in chapter 8, talking about macros. There is an example of a macro 
called def-watched, which prints a message each time the root binding of a 
var changes:

(defmacro def-watched [name & value]
  `(do
    (def ~name ~@value)
    (add-watch (var ~name)
                    :re-bind
                    (fn [~'key ~'r old# new#]
                      (println old# " -> " new#)))))

I understand almost everything, but I don't see why we have to use ~'keyand 
~'r rather than simply key# and r#. As I understand it, the first option (
~'var-name) would be useful to capture an external var inside the macro, 
but I don't see the point of doing it here, especially since ~'key is 
defined in the parameter list, so that it would anyway hide any external 
var. Could someone please help me understand this?

Thank you in advance,

Eric

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

Reply via email to