lua-users home
lua-l archive

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

on 8/19/07 8:39 PM, Anders Bergh at wrote:

> 2. shorter syntax for anonymous functions. I saw a patch somewhere
> that allowed "do ... end" syntax for these... really nice looking in
> my opinion.

I used to really want this and even made proposals in this regard. I've gone
back and studied the subtleties of Smalltalk blocks and realized that the
problem is a lot deeper than one would expect.

Assume we somehow recognized do as shorthand for creating a function:

    myMutex:withLock( do
        -- do stuff while holding the mutex
    end )

Or better yet, apply the same sort of rules to "do functions" as get applied
to strings and tables as parameters:

    myMutex:withLock do
        -- do stuff while holding the mutex

But now for the problem case:

    myMutex:withLock do
        return 42

Does the return exit the function and hence behave differently from a return

    while foo() do
        return 42

Or do we now have a non-local exit mechanism a la Smalltalk in which the
return will exit the function containing the do-block-pseudo-function?

If we go the non-local exit route -- which seems ideal as we start
constructing things that look like control constructs -- what do we do when
we want a return from just the local function. More syntax needed...

Stickier still, can you do a non-local-exit across a pcall?

I think there's potential fruitful opportunities here for Lua, but I think
they will require a fair amount of thought and may introduce enough
semantics shifts to force things to Lua 6 (or at least 5.5).