Hello Eric, You can rewrite this functionality with key# and r# instead of ~'key and ~'r and it would work just as well, it's only not necessary to use unique symbols here, because you are not using them in the function body anyway, so there is no danger of accidental var capture.
To be honest, i would rather use underscore symbols (written as ~'_ inside macro definition) to indicate that i won't use any of the first two parameters in the function body. Dňa sobota, 15. februára 2014 9:32:48 UTC+1 Eric napísal(-a): > > 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.