akh.core.trampoline
Version:
Akh trampoline for tail calls
24 lines (21 loc) • 395 B
JavaScript
/**
* Super basic trampoline for tail calls.
*/
/**
* Create a tail call.
*/
module.exports.tail = (f, x) => ({
f: f,
x: x,
__akhIsTail: true
})
/**
* Invoke `f` to completion by invoking all tail calls it returns.
*/
module.exports.trampoline = f => {
var value = f
while (value && value.__akhIsTail)
value = value.f(value.x)
return value
}