(recur
NAME ((NAME EXPRESSION) (NAME EXPRESSION) ...) EXPRESSION)
A recur
expression is a short-hand looping construct. In consists of three parts. The first is a name; the second is a sequence of names and expressions and the last is an expression. The first names the loop, the second is the variables that change for each iteration of the loop and the last expression is the body of the loop.
The evaluation of a recur
expression first evaluates all of the expressions in the sequence of names and expressions. Then, the names in the second part of the recur are bound to the results of those expressions, and the first name is bound to a procedure that accepts one argument for each name in the second part of the recur expression. Invoking that procedure will iterate the loop. Finally, the body is evaluated in the context of those bindings.
For example, this is an accumulator-style version of length:
(define (length l)
| (let loop ((lst l) (len 0)) (cond ((empty? lst) len) (else (loop (rest lst) (+ len 1)))))) |