I just wrote:
+---------------
| Though it would be a *lot* easier to read if written this way:
|
| > (loop for item in '(1 2 3 4 5)
| collect (let ((obj item)) (lambda () obj)))
|
| (#<Interpreted Function "LOOP FOR" {489410B1}>
| #<Interpreted Function "LOOP FOR" {48941141}>
| #<Interpreted Function "LOOP FOR" {489411D1}>
| #<Interpreted Function "LOOP FOR" {48941261}>
| #<Interpreted Function "LOOP FOR" {489412F1}>)
| > (mapcar 'funcall *)
|
| (1 2 3 4 5)
| >
+---------------
It also works [in CMUCL, at least] when compiled:
> (funcall
(compile nil
(lambda ()
(loop for item in '(1 2 3 4 5)
collect (let ((obj item)) (lambda () obj))))))
; Compiling LAMBDA NIL:
; Compiling Top-Level Form:
(#<Closure Over Function "LAMBDA NIL" {4895F0D1}>
#<Closure Over Function "LAMBDA NIL" {4895F0E9}>
#<Closure Over Function "LAMBDA NIL" {4895F101}>
#<Closure Over Function "LAMBDA NIL" {4895F119}>
#<Closure Over Function "LAMBDA NIL" {4895F131}>)
> (mapcar 'funcall *)
(1 2 3 4 5)
>
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607