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: Emanuel Berg
Subject: Re: Closures - do you understand them well?
Date: Fri, 09 Dec 2022 06:37:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

tomas wrote:

>>> OK, so is it the closures? Or the loops?
>>>
>>> Or ... the lamdas?
>>>
>>> (setq x 111)
>>>
>>> (setq f (lambda () x))
>>>
>>> (funcall f)
>>>
>>> (setq x 222)
>>>
>>> (funcall f)
>> 
>> Maybe I'm too tired, but I don't understand the question.
>> What's "it" in the first question?
>
> My gut reaction was such that the answer to Emanuel's
> question would have been "it's the bindings".

This is why you should never quote lambdas because if you do,
you get the intuitive result:

(let ((i 0)
      (funs '()))
  (while (< (setq i (1+ i))
            4)
    (push `(lambda () ,i)
          funs))
  (apply #'+ (mapcar #'funcall funs))) ; 6

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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