Subject: Re: bug#76132: Clojure-style auto-gensyms for macros

From: Eli Zaretskii <[email-masked]>
Date: Sat, 08 Feb 2025 09:54:59 +0200

> From: Tassilo Horn <[email-masked]>
> 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?