Daily Thought - 2024-07-26
< back to listClosures are currently boxed (i.e. allocated on the heap), so they can be represented by a single value on the stack. I don't think there's much to do about that, while the language is still untyped. With a more sophisticated type system, it will be possible to have closures live on the stack, with no extra heap allocations necessary.
And there are other sharp edges. A closure is consumed (its heap allocation is
removed) when evaluated by something like if
. But nothing prevents you from
copying the value that represents the closure and try to use that again. Or make
up a completely new value that then might or might not refer to a closure.
Right now, there's not much point in trying to fix stuff like that, I think. Things will get better, as the language develops. It's a process.