[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Closures - do you understand them well?
From: |
Emanuel Berg |
Subject: |
Re: Closures - do you understand them well? |
Date: |
Fri, 09 Dec 2022 22:31:21 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Michael Heerdegen wrote:
>> (let ((i 0)
>> (m (lambda (i)
>> (lambda () i)))
>> funs)
>> (while (< i 100)
>> (push (funcall m i) funs)
>> (cl-incf i))
>> (mapcar #'funcall funs))
>
> Yes, I think one can do this (the argument variable
> i shadows the variable of the same in the `let', but it also
> exists to conserve the value from the outside i so one can
> argue that it's ok to use the same name - it's semantically
> not incorrect anyway). Nice solution.
Okay so now it works for me as well, maybe some encoding in
messed up evaluation ...
>> (let ((i 0)
>> funs)
>> (while (< i 100)
>> (let ((j i))
>> (push (lambda () j) funs))
>> (cl-incf i))
>> (mapcar #'funcall funs))
>
> This is the trick that is used in the implementation of
> `dolist': create a binding that lives only inside the
> evaluation of the body of the loop in one iteration step.
Same, works.
--
underground experts united
https://dataswamp.org/~incal
- RE: [External] : Re: Closures - do you understand them well?, (continued)
- Re: [External] : Re: Closures - do you understand them well?, Emanuel Berg, 2022/12/10
- RE: [External] : Re: Closures - do you understand them well?, Drew Adams, 2022/12/10
- 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 <=
- 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, 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