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

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

Re: cl-loop - do you understand it well?


From: Michael Heerdegen
Subject: Re: cl-loop - do you understand it well?
Date: Sun, 18 Dec 2022 01:16:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Emanuel Berg <incal@dataswamp.org> writes:

> >> Jokes that I don't understand aside, why does this return 4?
> >>
> >> (require 'cl-lib)
> >>
> >> (cl-loop
> >>   for i from 0 to 1
> >>   collect (lambda () i) into funs
> >>   finally return (apply #'+ (mapcar #'funcall funs)) )
> >
> > Because of internal implementation details?
>
> I don't think so, rather it has something to do with how
> `cl-loop' is programmed.

This was a joke, right?

Anyway,

#+begin_src emacs-lisp
(macroexpand-1
 '(cl-loop
   for i from 0 to 1
   collect (lambda () i) into funs
   finally return (apply #'+ (mapcar #'funcall funs))))
  ==>
  (cl-block nil
    (let* ((i 0)
           (funs nil))
      (while (<= i 1)
        (setq funs (nconc funs (list (lambda nil i))))
        (setq i (+ i 1)))
      (apply #'+ (mapcar #'funcall funs))))
#+end_src

Nearly the same code as we had discussed.  But I guess this was all
clear to you (or not?).

Michael.




reply via email to

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