In the dash library I noticed the use of make-symbol
to avoid symbol conflicts during macro expansion.
(defmacro --filter (form list)
"Anaphoric form of `-filter'.
See also: `--remove'."
(declare (debug (form form)))
(let ((r (make-symbol "result")))
`(let (,r)
(--each ,list (when ,form (!cons it ,r)))
(nreverse ,r))))
From what I read in common lisp books, gensym
is used for things like this to create a unique symbols via.
(let ((r (cl-gensym "result"))) ...)
I'm confused because when I macro expand this kind of form.
(let ((result '(1 2 3 4)))
(--filter (> 2 it) result))
I get this and it looks like the symbol created with make-symbol
named result
is indeed conflicting with the result
that contains '(1 2 3 4)
.
In fact, when I copy the result of this macroexpansion and run it myself I get what I expect: nil.
(let ((result '(1 2 3 4)))
(let
(result)
(--each result
(when
(> 2 it)
(!cons it result)))
(nreverse result)))
But this seems to work. Instead of returning nil as I would expect from the macroexpansion. Why is this?
(let ((result '(1 2 3 4)))
(--filter (> 2 it) result))
;; => (1)