This has been a good intro to Common Lisp, as I've been comparing things to my JavaScript implementation of CHIP-8 (coughhttp://mrspeaker.github.io/CHIMP-8/cough) - but I'm having a difficult time parsing the `iterate` and `repeat` and `for` statements in there: what's the difference between them - and how does `for` relate to a C/JavaScript `for`?
iterate is a Common Lisp library that aims to be a replacement for loop, being cleaner (subjectively) and portably extensible: https://common-lisp.net/project/iterate/
`repeat` is an iterate clause that tells iterate to perform N iterations of the loop:
(iterate (repeat 3) (print 'beep))
BEEP
BEEP
BEEP
As for this particular `for`, it's an iterate clause that handles numeric iteration (among other things). So:
(iterate (for x :from 0)
(for y :from 10 :downto 7)
(print (list x y)))
Would give you:
(0 10)
(1 9)
(2 8)
(3 7)
iterate will terminate the loop the first time any one of its clauses runs out of values/iterations. So in the post I had something like
(iterate (repeat N)
(for x :from start)
...)
You could write this as
(iterate (for x :from start :below (+ start N))
...)
But manually calculating the ending value seems ugly to me. I know I want the loop to happen N times so I just say `(repeat N)` and let the computer figure out when it's time to be done.
I cannot answer your question the way you probably intended, but, for self learning:
ITERATE is an attempt at providing a generic LOOP, which is built into CL and is somewhat specified in the standard. REPEAT is part of the ITERATE package. ITERATE is extensible and can deal with lists and vectors uniformly (whereas with LOOP you "LOOP FOR x IN LIST" or "LOOP FOR x ACROSS VECTOR"; i.e. you have to change code when changing the type of sequence). Having said that: You can read LOOP/ITERATE in CL roughly like you can read FOR in JS. For details, see the Common Lisp HyperSpec[3].
If it is just for understanding the code: Just read it like natural language with indentation read like in python (i.e. something indented always belongs to the parent, which is one indentation level below - as an example see REPEAT and ITERATE, the indentation shows the relation between the two).