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

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

Closures - do you understand them well?


From: Michael Heerdegen
Subject: Closures - do you understand them well?
Date: Thu, 08 Dec 2022 16:36:12 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Hi,

Maybe you will have fun with this new exercise:

What is the return value of the following expression, and what's your
reasoning?  Answer without asking Emacs:

#+begin_src emacs-lisp
;; -*- lexical-binding: t -*-

(let ((i 0)
      (funs '()))
  (while (< (setq i (1+ i))
            4)
    (push (lambda () i)
          funs))
  (apply #'+ (mapcar #'funcall funs)))
#+end_src

Please no "you better write this as ... and then it returns ..."
answers: I mean this code and what it returns.


Have fun!

Michael.



reply via email to

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