[1] http://www.lispworks.com/documentation/lw60/CLHS/Body/m_do_d...
[1] http://www.lispworks.com/documentation/lw60/CLHS/Body/m_do_d...
In fact, a lot of SICP examples have you define a function within a function with a name like "iter" for TCO recursion. It'd work like that.
Edit: seems like gyka below confirms that's how it works. I should have read on!
For instance, the branch targets in a while loop are anonymous, right? But in the target language, you must have a named label for the instruction. Solution: machine-generated label.
> [1] http://www.lispworks.com/documentation/lw60/CLHS/Body/m_do_d...
'do' in most Lisps and Schemes is essentially an extended for loop, not a blocking construct. Of course, you could write
(do ((once nil t)) ; Scheme: (do ((once #f #t))
(once)
(thing-1)
(thing-2)
...)
or something, but that's silly.The blocking construct is in CL called PROGN and in Scheme called begin. Lambdas in CL get what's called an "implicit PROGN" around their bodies, so you can put however many forms you want inside and the value of the last is returned. It works the same in modern Scheme lambdas.
Calling PROGN/begin "do" is solely a Clojureism as far as I know.
Also an ANSI-CL-LOOP-ism:
(loop for x in '(1 2 3) do (print x) (print x))
1
1
2
2
3
3
Omit the do and you have a syntax error.