Is this an expected behavior?
Hi,I just spent about 30 minutes trying to figure out this behavior before i could find out how to solve it.
This might be an expected behavior (not by me) but if it is maybe someone can explain it to me?
Take this sample code
CL-USER 151 > (defun test ()
(loop with entries = '(())
for entry = (random 4)
until (= entry 3)
do (setf (first entries)
(append (first entries)
(list entry)))
finally return entries))
TEST
CL-USER 152 > (test)
(NIL)
CL-USER 153 > (test)
((0 1 0))
CL-USER 154 > (test)
((0 1 0 2))
CL-USER 155 > (test)
((0 1 0 2 0 2 1 1 2 2))
I was expecting the ENTRIES list to be reinitialized with each invocation of TEST but that doesn't seem to be happening, any idea why? I noticed that if I replace the quoted list with (LIST '()) everything works as I expected. This is not specific to the LOOP, if i remove the ENTRIES declaration to a LET form it still behaves the same. Does this have to do with some compilation magic?
Regards,
Alex Paes