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 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"

        button "Goodbye" do

    end : run()

As compared to something like:

    dialog( function( dlg )

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

        button "Goodbye" (function()
        end )

    end ) : run()

Or more likely:

    local dlg

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

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



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

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.