GNU bug report logs -
#76132
Clojure-style auto-gensyms for macros
Previous Next
Reported by: Tassilo Horn <tsdh <at> gnu.org>
Date: Fri, 7 Feb 2025 21:13:02 UTC
Severity: wishlist
Tags: patch
Done: Tassilo Horn <tsdh <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Sun, 23 Feb 2025 10:11:08 +0100
with message-id <87zfidowk3.fsf <at> gnu.org>
and subject line Re: bug#76132: Clojure-style auto-gensyms for macros
has caused the debbugs.gnu.org bug report #76132,
regarding Clojure-style auto-gensyms for macros
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
76132: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76132
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
Tags: patch
Hi all,
in a recent bug report the topic macro hygiene came up, i.e., that a
macro which introduces local bindings in its expansion better uses
uninterned symbols for those in order not to clash with code passed as
macro arguments which are spliced into the expansion.
Clojure has a very convenient feature to make that easy. While you can
write such macros traditionally like
(defmacro foo [x y]
(let [xv (gensym "x")
yv (gensym "y")]
`(let [,xv ,x
,yv ,y]
(do-stuff (* ,xv ,xv) (* ,yv ,yv)))))
you can also write much more concise and convenient
(defmacro foo [x y]
`(let [xv# ,x
yv# ,y]
(do-stuff (* xv# xv#) (* yv# yv#))))
where each symbol ending in # will be replaced by a unique gensymed
symbol (per name). The expansion of the two macros is the same.
Would there be interest in adding something like that to Elisp?
I've attached a proof-of-concept implementation where the feature is
provided by a macro with-uninterned-symbols [1] which you simply wrap
around your backquoted form.
[1] In Clojure, it's a feature of the reader triggered by backquote.
In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.48, cairo version 1.18.2) of 2025-02-07 built on thinkpad-t440p
Repository revision: 1751739152149608d28853782ce53b0b9a749bb2
Repository branch: master
System Description: Arch Linux
Configured using:
'configure --without-native-compilation --with-modules --with-pgtk'
[clojure-macro.el (text/patch, attachment)]
[Message part 5 (message/rfc822, inline)]
Stefan Kangas <stefankangas <at> gmail.com> writes:
> So what's the conclusion here?
Macros (in the presence of eager macro expansion) are hard. :-)
> Should this bug be closed, or is there more left to discuss?
No, I'm closing it now.
Bye,
Tassilo
This bug report was last modified 146 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.