Re:No Stinking Loops
by erik_seaberg on Saturday December 16, 2023 @11:04PM
(#38670227)
Most platforms make some kind of loop into a primitive, but in Common Lisp
(dotimes (i 10)
(print i))
is just a predefined macro that might expand into primitives like (BLOCK NIL
(LET ((I 0))
(TAGBODY
#:LOOP-2867
(IF (>= I 10)
(GO #:END-2868))
(PRINT I)
(PSETQ I (1+ I))
(GO #:LOOP-2867)
#:END-2868
(RETURN-FROM NIL (PROGN NIL)))))
The claim is that by expressing programs in terms of these array primitives, you (a) can have those primitives be super optimised and (b) better see what the program is actually about without worrying too much about eg what names to give all the loop counters, all the other intermediate state associated with iteration, etc.