|
From: | Stefan Monnier |
Subject: | Re: Closures - do you understand them well? |
Date: | Thu, 08 Dec 2022 15:01:50 -0500 |
User-agent: | Gnus/5.13 (Gnus v5.13) |
>> (let ((funs '())) >> (loop for i from 1 to 3 >> do (push (lambda () i) funs)) >> (apply #'+ (mapcar #'funcall funs))) >> ;=> 12 > > I guess this depends a bit on the implementation of `loop'. I haven't checked but for the similar code using `dolist` or `dotimes` Common Lisp indeed leaves it unspecified ig the same `i` binding is used through the loop or if a different binding is used at each iteration. In ELisp, both `dotimes` and `dolist` create a new binding for `i` at each iteration of the loop. Stefan
[Prev in Thread] | Current Thread | [Next in Thread] |