loop
Summary
Generates a stack-safe recursive function.
Description
Colloquially known as "trampoline" this function allows you to implement
stack-safe recursive functions. You must use recur
to bootstrap the next
recursive call and cease
to signal the exit condition and the return value.
Examples
Without tail call optimization recursive functions can exhaust the stack:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
With loop/recur you can build the same recursive function without fear:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Parameters
Name | Type | Description |
---|---|---|
fn | function |
Return
function