[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: something *very* strange (to *me*). Please help!
- To: email@example.com
- Subject: Re: something *very* strange (to *me*). Please help!
- From: Pierpaolo Bernardi <bernardp@CLI.DI.Unipi.IT>
- Date: Fri, 3 Oct 1997 17:55:33 +0200 (MET DST)
- In-reply-to: <9710038758.AA875892986@inet.stknhlg.com> from "firstname.lastname@example.org" at Oct 3, 97 05:35:39 pm
- Organization: Centro di Calcolo - Dipartimento di Informatica di Pisa - Italy
> Sorry about such a non-descriptive subject. I really have no idea
> what's going on!
> In CLISP:
> (let ((l (do ((i 0 (1+ i)) r) ((= i 3) (nreverse r))
> (push #'(lambda () i) r))))
> (mapcar #'funcall l))
> ==> (3 3 3)
> I would expect (0 1 2)
> What is going on?
> How do I get the desired result?
> (declaring i special doesn't change anything)
To understand what's going on, try macroexpanding the DO form.
Whether the variables in the DO are SETQed or rebound is
implementation dependent. It appears that in Clisp one variable is
shared by all the functions.
If you want a different behaviour, you should write exactly what you want.
e.g. (not tested)
(let ((l (labels ((fun (i r)
(if (= i 3)
(fun (+ i 1) (cons (lambda () i) r)))))
(fun 0 '()))))
(mapcar #'funcall l))
> Sam Steingold