I was looking clojure.core
's macro implementation of and
and I noticed that some of the let
bindings in this source file's macros end their variable name with and octothorpe (#
).
Upon further inspection with the following code...
(defn foo# [] 42)
(foo#) ; => 42
...I realized that octothorpe is just a valid symbol (at least when included on the end).
So, my question is, why do these core macros end their binding symbols with a hash character? Is there some specific implied meaning or convention I am missing here?
The # at the end of a symbol is interpreted specially by the reader as a shortcut for gensym.
(gensym "foo")
;=> foo3
(defmacro hygienic []
`(let [foo# 42] foo#))
(hygienic)
;=> 42
(macroexpand '(hygienic))
;=> (let* [foo__1__auto__ 42] foo__1__auto__)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With