lua-users home
lua-l archive

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



On 5-Feb-07, at 12:23 PM, Mark Hamburg wrote:

on 2/5/07 8:26 AM, Rici Lake at lua@ricilake.net wrote:

The complex part of implementing smalltalk blocks is the correct
handling of ^ (return) inside a block. This could be macro-expanded
into call/cc, if you have call/cc (actually, only a very limited form
of call/cc is necessary), but I don't see any obvious way of doing
that in Lua without introducing a coroutine; furthermore, the
coroutine solution may fail unexpectedly because Lua coroutines
lack delimiters.

A useful bit of subtlety to be aware of.

Fundamentally, blocks are a great way to enable non-guru programmers to
implement control structure like entities, but without support for non-local return (or break for that matter), they won't really feel quite like control constructs and adding such support potentially leads to continue capture
issues though those can be addressed by declaring that a function scope
closes the first time we exit from the function.

Yes, exactly, although I would have said "declaring that the lifetime
of a continuation ends the first time we exit".

The Java 7 blocks proposal explicitly recognizes this situation by defining a new exception, UnmatchedNonlocalTransfer. That's a little bizarre, since it effectively replaces a return to a static continuation with a return to a dynamic continuation (that is, a catch block), but in practice I suspect few programmers will stumble upon it.

The same implementation could easily work in Lua, if the feature were deemed to be useful.