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: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Tassilo Horn <tsdh <at> gnu.org>
Cc: 76132 <at> debbugs.gnu.org
Subject: bug#76132: Clojure-style auto-gensyms for macros
Date: Sun, 09 Feb 2025 18:34:55 -0500
> Why?

I'd ask the author of the code.

> I would expect that it's one set of uninterned symbols per expansion.

Try:

    (defmacro my-foo (exp)
      (with-uninterned-symbols
       `(let ((x$ 6))
          (+ x$ ,exp))))

and then check (equal (macroexpand '(my-foo r)) (macroexpand '(my-foo r)))
[ Admittedly, this all depends on when `with-uninterned-symbols` is
  macro-expanded, but in most cases it will be macro-expanded once and
  for all when the macro is defined.  ]

> Doesn't that contradict your statement?

Apparently not.  🙂

> Oh, and obviously you made me curious about those weird corner cases.
> Please elaborate! ;-)

I wish I could.  I'm starting to wonder if I dreamed it.
The best I could come up with is:

    (defmacro my-countref-let (var form &rest body)
      (with-uninterned-symbols
       `(let ((x$ ,form)
              (count$ 0))
          (cl-symbol-macrolet ((,var (progn (cl-incf count$) x$)))
            (unwind-protect
                (progn ,@body)
              (message "%S ref'd %d times" ',var count$))))))

where (my-countref-let v1 67 (my-countref-let v2 89 (+ v1 v2))) will say
that `v2` was referenced twice and `v1` zero times (at least if that
macro is byte-compiled).


        Stefan





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.