[Openmcl-devel] Closures

Stas Boukarev stassats at gmail.com
Sun Apr 20 04:38:42 PDT 2014


Taoufik Dachraoui <dachraoui.taoufik at gmail.com> writes:

> Hi
>
> Can someone explain the following:
>
> ? (let ((fn nil)) (dotimes (k 2) (push (lambda () (print k)) fn)) (dolist
> (f fn) (funcall f)))
>
> 2
> 2
> NIL
> ? (let ((fn nil)) (dotimes (k 2) (let ((r k)) (push (lambda () (print r))
> fn))) (dolist (f fn) (funcall f)))
>
> 1
> 0
> NIL
> ? (defvar r 10)
> R
> ? (let ((fn nil)) (dotimes (k 2) (let ((r k)) (push (lambda () (print r))
> fn))) (dolist (f fn) (funcall f)))
>
> 10     ?????
> 10     ?????
> NIL
Special variables do not produce closures, only lexical ones do.

-- 
With best regards, Stas.



More information about the Openmcl-devel mailing list