lua-users home
lua-l archive

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


On Tue, Sep 15, 2009 at 5:17 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> On Tue, Sep 15, 2009 at 10:00 AM, David Kastrup <dak@gnu.org> wrote:
>> But I like the things that are just syntactic sugar in Lua: it means
>> that you can exhaustively explain them in more basic terms in one
>> sentence.
>
> OK, this is sugar we know so well:
>   - obj:method() becomes obj.method(obj)
>
> But in the case of a obj:method _without_ parentheses, then there is a
> somewhat more elaborate expansion as a closure.
>
> That feels manageable.
>
> First-class ':' has some cute advantages, it is an operator and
> presumably has a metamethod, so that we can finally distinguish
> between method and table lookup, _if needed_.
>
> But I worry about the complexity of the change, possible performance
> implications, and more semantics that, yes, have to be explained ...

What about this idea?
When functions have a metatable and when that metatable has a field
"__colon", then the expression

  f:method

without an argument list, of course, would just return the result of:

  getmetatable(f).__colon(f, "method")

Cheers,
  Eduardo Ochs
  eduardoochs@gmail.com
  http://angg.twu.net/