[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Closures - do you understand them well?
From: |
tomas |
Subject: |
Re: Closures - do you understand them well? |
Date: |
Mon, 12 Dec 2022 06:16:30 +0100 |
On Mon, Dec 12, 2022 at 02:18:04AM +0100, Michael Heerdegen wrote:
> <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
^^^
To me, that one (well, if you squint, the others too)
counts as a compile time binding, of sorts. Or well,
pre-compile or something.
It was the "poor human's closure" in pre-lexical times,
after all.
> #+begin_src emacs-lisp
> (setq funs
> (cons
> (list 'lambda nil i)
> funs))
> #+end_src
Yes, the binding of i is effective before the lambda
expression is "compiled" (whatever that means when you
are playing interpreter, but it still means something,
no?)
> 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.
FWIW, I find those languages (the ones trying to be nice)
the most interesting. But they can be confusing, too :-)
Cheers
--
t
signature.asc
Description: PGP signature
- Re: [External] : Re: Closures - do you understand them well?, (continued)
- Re: [External] : Re: Closures - do you understand them well?, Emanuel Berg, 2022/12/15
- 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, 2022/12/11
- Re: Closures - do you understand them well?,
tomas <=
- 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
- Re: Closures - do you understand them well?, Michael Heerdegen, 2022/12/10