[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: |
Sun, 11 Dec 2022 03:24:06 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Tassilo Horn <tsdh@gnu.org> writes:
> > Would this be a valid solution?
> >
> > #+begin_src emacs-lisp
> > (let ((i 0) (funs))
> > (while (<= (cl-incf i) 100)
> > (push (apply-partially #'identity i) funs))
> > (nreverse funs))
> > #+end_src
>
> Apparently it works although I don't see why.
I do think the above is a valid solution.
> Where's the difference to
> this inlined version which returns (101 ... 101)?
>
> (let ((i 0) (funs))
> (while (<= (cl-incf i) 100)
> (push (lambda (&rest args2)
> (apply #'identity (append (list i) args2)))
> funs))
> (mapcar #'funcall (nreverse funs)))
Well - `apply-partially' is a function and I use a simple function call,
so it is precisely not just something inlined: The important point is
that only the _value_ of the variable i passed, not the variable or
a reference to it:
#+begin_src emacs-lisp
(let ((i 27))
(apply-partially #'identity i))
==>
(closure
((args . (27))
(fun . identity))
(&rest args2)
(apply fun (append args args2)))
#+end_src
Michael.
- Re: Closures - do you understand them well?, (continued)
- 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 <=
- Re: Closures - do you understand them well?, Tassilo Horn, 2022/12/11
- 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
- Iteration macros (was: [External] : Re: Closures - do you understand them well?), Stefan Monnier, 2022/12/10
- RE: Iteration macros (was: [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/21
- Re: Closures - do you understand them well?, Emanuel Berg, 2022/12/08
- Re: Closures - do you understand them well?, Michael Heerdegen, 2022/12/08
- Re: Closures - do you understand them well?, tomas, 2022/12/08
- Re: Closures - do you understand them well?, Emanuel Berg, 2022/12/09