GNU bug report logs - #76132
Clojure-style auto-gensyms for macros

Previous Next

Package: emacs;

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tassilo Horn <tsdh <at> gnu.org>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 76132 <at> debbugs.gnu.org
Subject: bug#76132: Clojure-style auto-gensyms for macros
Date: Sat, 08 Feb 2025 09:54:59 +0200
> From: Tassilo Horn <tsdh <at> gnu.org>
> Date: Fri, 07 Feb 2025 22:12:14 +0100
> 
> 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'm very hesitant to extend the Emacs Lisp language with such
features, when this can be had for a price of a simple function call.
We have enough magic names and punctuation characters already, and
they get in the way of code readability.

Stefan, WDYT?




This bug report was last modified 147 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.