[toronto-lisp] access to previous value in loop

Justin Giancola justin.giancola at gmail.com
Fri Jan 8 05:44:55 UTC 2010


Abram--I stumbled upon equals-then assignment clauses when reading up  
on something else I'd needed to do with loop:

(loop repeat 5
       for prev = 0 then i
       for i = 17 then (1+ i)
       collect (cons i prev))
; => ((17 . 0) (18 . 17) (19 . 18) (20 . 19) (21 . 20))

note: these clauses are evaluated in order so this example wouldn't  
work if the equals-then clause for i appeared before the one for prev.  
if the prev clause comes first, it can take the value of i from the  
previous iteration before it's updated.


Justin




More information about the toronto-lisp mailing list