rec is Coalton’s named-recursion form, similar to Scheme’s “named-let”.
Syntax
(rec ⟨name-spec⟩ ((⟨var⟩ ⟨init⟩) ...)
⟨body⟩)
;; ⟨name-spec⟩ := ⟨name⟩
;; | (⟨name⟩ ⟨type⟩)
Semantics
recis useful for iteration.⟨name⟩should name a function to be called tail recursively.- The recursive name can optionally carry an explicit type.
- The names
goor%are often used. - Tail recursion is not enforced.
⟨body⟩has an implicitprogn.
Example
(rec % ((i n) (acc 0))
(if (== i 0)
acc
(% (1- i) (+ acc i))))