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: Ship Mints <shipmints <at> gmail.com>
To: Tassilo Horn <tsdh <at> gnu.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 76132 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: bug#76132: Clojure-style auto-gensyms for macros
Date: Sat, 8 Feb 2025 08:02:18 -0500
[Message part 1 (text/plain, inline)]
I've seen many unhygienic macros (found the hard way) and written some
myself out of laziness. It's a nice idea to encourage safer lazy macro
writing.

I prefer a hat ^ prefix as it is easier to read, rather than a dollar $
suffix which seems muddled to my eye.

I found no evidence of symbols with a ^ prefix in the Emacs code base or in
the elpa packages I use so would risk less conflict than $ which I have
seen around. I'd highlight these hat-prefixed symbols in some nice new
font-lock face.

(defmacro sm/test (x y)
  (with-uninterned-symbols
   `(let ((^foo ,x)
          (^bar ,y))
      (list :args `(,^foo . ,^bar)
            :add   (+ ^foo ^bar)
            :sub   (- ^foo ^bar)
            :mul   (* ^foo ^bar)
            :div   (/ ^foo ^bar)))))

-Stephane

On Sat, Feb 8, 2025 at 3:30 AM Tassilo Horn <tsdh <at> gnu.org> wrote:

> Eli Zaretskii <eliz <at> gnu.org> writes:
>
> >> 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.
>
> In my opinion, readability is the key point of the feature.  With the
> regular "declare the locals you need to introduce beforehand and then
> splice them into the expansion" approach, the distinction between locals
> and spliced-in macro args gets lost.  With the suggested
> with-uninterned-symbols macro, it's clear that foo$ is a local defined
> in the expansion while ,foo is something from "the outside".
>
> I'm not booked on the $-suffix, though.  It's just easy to type, stands
> out a bit and usually isn't used in the wild.
>
> Bye,
> Tassilo
>
>
>
>
[Message part 2 (text/html, inline)]

This bug report was last modified 149 days ago.

Previous Next


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