[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Closures - do you understand them well?
From: |
Michael Heerdegen |
Subject: |
Re: Closures - do you understand them well? |
Date: |
Mon, 12 Dec 2022 02:18:04 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
<tomas@tuxteam.de> writes:
> > > (let ((i 0)
> > > funs)
> > > (while (< i 100)
> > > (push `(lambda () ,i) funs)
> > > (cl-incf i))
> > > (mapcar #'funcall funs))
> >
> > Yes, but here there is no "new binding" exactly, rather the
> > value is hard-coded onto the lambda ...
>
> Look closely. There is one. Just at macro expansion (aka compile)
> time.
?!?
The expansion of (push `(lambda () ,i) funs) is
#+begin_src emacs-lisp
(setq funs
(cons
(list 'lambda nil i)
funs))
#+end_src
No binding is created here, neither at compile time (where the symbol i
is not touched), nor at run-time (where the value of `i` is just passed
as an argument to `list').
Stefan would say that this accumulates a list of function expressions in
FUNS, not a list of functions, strictly speaking. Works only because
the Lisp interpreter is made to be nice to everyone.
Michael.
- RE: [External] : Re: Closures - do you understand them well?, (continued)
- Re: Closures - do you understand them well?, tomas, 2022/12/08
- Re: Closures - do you understand them well?, Michael Heerdegen, 2022/12/09
- Re: Closures - do you understand them well?, tomas, 2022/12/09
- Re: Closures - do you understand them well?, Tassilo Horn, 2022/12/09
- Re: Closures - do you understand them well?, Michael Heerdegen, 2022/12/09
- Re: Closures - do you understand them well?, Emanuel Berg, 2022/12/10
- Re: Closures - do you understand them well?, Emanuel Berg, 2022/12/10
- Re: Closures - do you understand them well?, tomas, 2022/12/10
- Re: Closures - do you understand them well?,
Michael Heerdegen <=
- Re: Closures - do you understand them well?, tomas, 2022/12/12
- Re: Closures - do you understand them well?, Michael Heerdegen, 2022/12/12
- Re: Closures - do you understand them well?, Emanuel Berg, 2022/12/22
- Re: Closures - do you understand them well?, tomas, 2022/12/23
- Re: Closures - do you understand them well?, Emanuel Berg, 2022/12/10
- Re: Closures - do you understand them well?, Michael Heerdegen, 2022/12/09
- Re: Closures - do you understand them well?, Tassilo Horn, 2022/12/10
- Re: Closures - do you understand them well?, Emanuel Berg, 2022/12/10
- Mutation - do you understand it really? (was: Closures - do you understand them well?), Stefan Monnier, 2022/12/10
- Re: Mutation - do you understand it really?, Michael Heerdegen, 2022/12/10