Consider the following cl-loop
:
(cl-loop for x across "abc"
for y across "123"
concat (string x y))
This evaluates to "a1b2c3"
, i.e. it zips both strings together. However, if I look at the expansion of cl-loop
it seems like that should not be possible, as
(pp-macroexpand-expression
'(cl-loop for x across "abc"
for y across "123"
concat (string x y)))
expands to (comments by me)
(cl-block nil
(let*
((--cl-vec-- "abc") ; --cl-vec-- set to "abc"
(--cl-idx-- -1)
(x nil)
(--cl-vec-- "123") ; --cl-vec-- set again, this time to "123"
(--cl-idx-- -1)
(y nil)
(--cl-var-- ""))
(while
(and
(setq --cl-idx--
(1+ --cl-idx--))
(< --cl-idx--
(length --cl-vec--))
(progn
(setq x
(aref --cl-vec-- --cl-idx--)) ; A
(setq --cl-idx--
(1+ --cl-idx--)))
(< --cl-idx-- ; C
(length --cl-vec--)))
(setq y
(aref --cl-vec-- --cl-idx--)) ; B
(cl-callf concat --cl-var--
(string x y)))
--cl-var--))
However, when I try to evaluate that it only returns "12"
, which is expected, since x
will refer to "1"
at A
and y
will refer to B
at A
, and then --cl-idx--
will be 4
in the next iteration C
and thus end the loop.
That's not how the original code can work, so cl-loop
cannot expand into that form. How can I get the actual macro expansion with proper identifiers?