[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cl-loop - do you understand it well?
From: |
Michael Heerdegen |
Subject: |
Re: cl-loop - do you understand it well? |
Date: |
Wed, 21 Dec 2022 09:12:12 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Emanuel Berg <incal@dataswamp.org> writes:
> > (cl-block nil
> > (let* ((i 0)
> > (funs nil))
> > (while (<= i 1)
> > (setq funs (nconc funs (list (lambda nil i))))
> > (setq i (+ i 1)))
> > (apply #'+ (mapcar #'funcall funs))))
> >
> No, where does the 4 come from?
There are two closures in FUNS, and both share the same lexical variable
i. When the closures are `funcall'ed i is bound to 2, which is the
value i had when the loop is exited. 2*2=4.
The goal of this exercise was to demonstrate that closures share
modifiable environments instead of copies of values present at closure
creation time.
Michael.
- Re: cl-loop - do you understand it well?, (continued)
- Re: cl-loop - do you understand it well?, Michael Heerdegen, 2022/12/11
- Re: cl-loop - do you understand it well?, Emanuel Berg, 2022/12/15
- Re: cl-loop - do you understand it well?, Stefan Monnier, 2022/12/15
- Re: cl-loop - do you understand it well?, Emanuel Berg, 2022/12/17
- Re: cl-loop - do you understand it well?, Michael Heerdegen, 2022/12/15
- Re: cl-loop - do you understand it well?, Emanuel Berg, 2022/12/17
- Re: cl-loop - do you understand it well?, Michael Heerdegen, 2022/12/17
- Re: cl-loop - do you understand it well?, Emanuel Berg, 2022/12/20
- Re: cl-loop - do you understand it well?,
Michael Heerdegen <=