Open Luis-Henriquez-Perez opened 3 years ago
Accumulation variables need to be complete before after-do
runs, so it wouldn't work to allow collect
in them. For example, updates to accumulation variables, such as coercing their type or correcting the order of a list made in reverse, need to happen before code in after-do
could try to access them.
It would only work in before-do
, and I think it less expected to allow it in before-do
without also allowing it in after-do
. Neither cl-loop
or iterate
allow this, as far as I can tell.
Besides, accumulating into a variable in before-do
can also just be done by setting the variable in with
, though this might involve knowing more about how the macro works.
(loopy (with (loopy-result '(initial-value)))
(nums i 1 3)
(collect i))
;; Currently expands to:
;; => (initial-value 1 2 3)
(let* ((loopy-result '(initial-value)))
(let* ((loopy-result-last-link-129 (last loopy-result)))
(let* ((i 1)
(nums-increment127 1)
(nums-end128 3))
(let ((loopy-first-iteration t))
(progn
(while (<= i nums-end128)
(cond (loopy-result-last-link-129
(setcdr loopy-result-last-link-129
(list i))
(setq loopy-result-last-link-129
(cdr loopy-result-last-link-129)))
(loopy-result
(setq loopy-result-last-link-129 (last loopy-result))
(setcdr loopy-result-last-link-129 (list i))
(setq loopy-result-last-link-129
(cdr loopy-result-last-link-129)))
(t
(setq loopy-result (list i)
loopy-result-last-link-129 loopy-result)))
(setq i (+ i nums-increment127))
(setq loopy-first-iteration nil))
loopy-result)))))
So, while this would be nice to have, it currently would only work for before-do
, where it isn't particularly needed anyway. I think this issue should stay open, but I'm not expecting things to change without majorly complicating how code is generated.
Some clauses in iter don't accept arbitrary clauses such as
before-do
.For example, I would expect to be able to use
collect
withininitially-do
. But iter does not check inbefore-do
(and I'm assuming it also does not do so for similar clauses likeafter-do
either). I think it should.