[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Replacement for Common Lisp's GENSYM in Emacs Lisp
From: |
Helmut Eller |
Subject: |
Re: Replacement for Common Lisp's GENSYM in Emacs Lisp |
Date: |
Tue, 04 May 2010 15:41:49 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
* Stefan Monnier [2010-03-07 20:06+0100] writes:
>> This is actually a non-trivial problem. Best approach would probably be
>> to do something similar to how they generate universally unique IDs.
>
> The best approach often is to not use "unique symbols" at all. A common
> technique is to rely on lexical scoping to precisely control which
> variables are visible to each part of a macro's argument during its
> evaluation. E.g.:
>
> (defmacro dotimes (xl e)
> (let ((x (car xl))
> (l (cadr xl)))
> `(let ((body (lambda (,x) ,e))
> (list ,l))
> (while (consp list)
> (funcall body (car list))
> (setq list (cdr list))))))
>
> Notice how the expressions `l' and `e' are evaluated in a context where
> neither of `body', nor `list' exist. No need for gensym.
What makes you think that body and list aren't bound in e?
Helmut
Re: Replacement for Common Lisp's GENSYM in Emacs Lisp, Pascal J. Bourguignon, 2010/05/04