[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: something *very* strange (to *me*). Please help!
- To: <clisp-list@ma2s2.mathematik.uni-karlsruhe.de>
- Subject: Re: something *very* strange (to *me*). Please help!
- From: Steve Haflich <smh@Franz.COM>
- Date: Fri, 03 Oct 1997 09:17:56 -0700
- In-reply-to: Your message of "Fri, 03 Oct 1997 17:54:52 BST." <199710031555.RAA18839@helen.cli.di.unipi.it>
From: Pierpaolo Bernardi <bernardp@CLI.DI.Unipi.IT>
> (let ((l (do ((i 0 (1+ i)) r) ((= i 3) (nreverse r))
> (push #'(lambda () i) r))))
> (mapcar #'funcall l))
To understand what's going on, try macroexpanding the DO form.
Agreed.
If you want a different behaviour, you should write exactly what you want.
(let ((l (labels ((fun (i r)
(if (= i 3)
(nreverse r)
(fun (+ i 1) (cons (lambda () i) r)))))
(fun 0 '()))))
(mapcar #'funcall l))
This code is rather different from the original. I think the
following captures more succinctly the semantic point between the
original code and what was wanted:
(let ((l (do ((i 0 (1+ i)) r) ((= i 3) (nreverse r))
(let ((j i)) ; Only this form is added. -smh
(push #'(lambda () j) r)))))
(mapcar #'funcall l))