lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Mar 1, 2012, at 3:36 AM, Jay Carlson wrote:

>> If you really want to do control flow, you need blocks rather than closures with the key difference being how return statements work. A block still exists in the control context of its enclosing scope. A closure is its own control context.
>> From Scheme's point of view, part of the environment for blocks is the
> current continuation of the enclosing method; that is, the method has
> a hidden "^" variable in its scope containing a function which will
> fall off the end of the method when called. Blocks may capture this
> lexically. This "^" upvalue function is guaranteed to be called from a
> tail position, so it's a goto, and because it's hidden it can't be
> captured. It does leave one with the lingering question, "Say, what
> *would* happen if I stored [^3+4] somewhere? Would *this current*
> function return again?"
> This is a particularly mean and nasty question to ask of such a noble
> language, so implementations generally avoided the question.

Nice. I hadn't thought about it that way. But of course continuations are how one potentially expresses all control flow.