lua-users home
lua-l archive

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


On Fri, Jul 19, 2013 at 5:46 PM, Coda Highland <chighland@gmail.com> wrote:
> My first thought is: What's wrong with the colon operator? What
> problem does this suggestion actually solve?


as i understand it, it's not (mostly) about the color or dot
operators, but about being able to use a bound method as a value.

a slightly better proposal could be:  don't modify the current
operators, but add this syntax:

local f = o:m

as syntax sugar to:

local f = function(...) return o.m(o, ...)  end

i think it's better than Greg's proposal because it doesn't magically
changes the meaning of an existing operator (dot), instead uses a
currently invalid syntax.

of course, Greg assumed that being in the core would somehow avoid
closure creation, but i doubt that would be simple.  Still, it
postpones it until (if) it's needed, so it wouldn't have any impact on
any code that doesn't need it.

said that, i don't see the need, it's not so ugly to define a
"bind(o,m)" utility:

function bind(o,m)
    return function(...) return o[m](o,...) end
end

then, you could get a bound method as:

local f = bind(o,'methodname')

--
Javier