4.5 Recursion
Rhombus functions defined with fun can be recursive, of course, but the recur form offers a shorthand for the case that a recursive function is used just once and is better written inline. Iteration with for is also a kind of recursion, but recur supports non-tail recursion, instead of only iterative loops.
expression | |||
|
Racket and Scheme programmers will recognize this form as a kind of “named let.”
To enable the immediate call of id, each bind_maybe_kw_opt must include a “default” expression, and the immediate call is like supplying zero arguments. Thus, each “default” expression is really an initial-value expression. The binding of id within the body block, however, is a function where only keyword arguments are optional. The default value for a keyword argument in a recursive call, meanwhile, is whatever was supplied for the enclosing call, with the effect that keyword arguments are automatically propagated in a recursive call. That treatment of keyword arguments is different from a fun-defined function that calls itself.
Beware that when maybe_res_annot specifies a result annotation using ::, the annotation is checked on every recursive call. In that case, no recursive calls are in tail position.