help-gnu-emacs
[Top][All Lists]
Advanced

[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:51 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

* Stefan Monnier [2010-03-08 05:55+0100] writes:

>>>   (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?
>
> Nothing, but luckily it doesn't make any difference whether they are
> or not.

Your "dotimes" macro produces:

(let ((list '(1)) (result ()))
  (dotimes (i '(1 2 3)) (push list result))
  result) => ((3) (2 3) (1 2 3))

While a version which doesn't shadow "list" produces this:

(let ((list '(1)) (result ()))
  (dolist (i '(1 2 3)) (push list result))
  result) => ((1) (1) (1))

Helmut


reply via email to

[Prev in Thread] Current Thread [Next in Thread]