help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Closures - do you understand them well?


From: Tassilo Horn
Subject: Re: Closures - do you understand them well?
Date: Sun, 11 Dec 2022 10:13:28 +0100
User-agent: mu4e 1.9.4; emacs 30.0.50

Michael Heerdegen <michael_heerdegen@web.de> writes:

>> 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

Thanks, that explains it.

Bye,
Tassilo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]