lua-users home
lua-l archive

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


on 1/31/08 9:15 AM, Roberto Ierusalimschy at roberto@inf.puc-rio.br wrote:

> The Lua syntax has changed very little over the years. In particular,
> the sugar f{} is in Lua since its first version (15 years ago), and the
> sugar f"" is there since version 3.1 (10 years).
> 
> I would say Lua is quite mature now, and it is not going to become more
> complicated than it is.

Well, there are the calls for similar sugar for passing functions, but those
also need sugar for creating functions. But with such sugar ones gets to
write things like:

    dialog do( dlg )

        button "Hello" do
            print "Hello"
        end

        button "Goodbye" do
            dlg:close()
        end

    end : run()

As compared to something like:

    dialog( function( dlg )

        button "Hello" (function()
            print "Hello"
        end )

        button "Goodbye" (function()
            dlg:close()
        end )

    end ) : run()

Or more likely:

    local dlg

    dlg = dialog{
    
        button{
            title = "Hello",
            action = function() print "Hello" end
        },

        button{
            title = "Goodbye",
            action = function() dlg:close() end
        }

    }

    dlg:run()

On the other hand, if this sort of chained function calling approach is
encouraged, then it might be nice if there were easier ways to go about it
than writing:

    function button( title )
        assert( type( title ) == 'string' )
        return function( action )
            assert( type( action ) == 'function' )
                -- Actually, we need a way to assert that it's callable
            -- make a button
        end
    end

Furthermore, the above code almost certainly does the wrong thing if you
don't pass the action argument. Then you just end up with a function that
goes nowhere without a particularly good way to do a runtime check --
particularly if we don't want to make all function calls more expensive.

Mark