for* is the sequential counterpart to for.
Syntax
(for (⟨binding-clause⟩...)
[:returns ⟨expr⟩]
[{:while | :until | :repeat} ⟨expr⟩]
⟨body⟩...)
;; ⟨binding-clause⟩ := (⟨var⟩ ⟨init-expr⟩ ⟨step-expr⟩)
Semantics
- Initializers follow
let*-style top-to-bottom scoping. - Step expressions are also performed top to bottom.
- Use
for*when later loop state should depend on earlier updated values. :whileloops while the condition is true.:untilloops until the condition is true.:repeatloops a certain fixed number of times.:returnsspecifies what to return when the loop exits, either normally or by(break).- No
:returnsmeans the loop unifies withVoid. - Use
for*when later steps should see earlier updated values.
Example
(for* ((x 1 (+ x y))
(y 1 x))
:until (> x 10)
(show x))