lua-users home
lua-l archive

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


On Tue, Sep 27, 2011 at 00:16, Mark Hamburg <mark@grubmah.com> wrote:
> On Sep 26, 2011, at 12:06 AM, steve donovan wrote:
>
>> A little consistency: we know that f:method has no meaning as an
>> expression. It has been suggested that it can be given a consistent
>> meaning as function(...) return f:method(...) end, that is, it is a
>> closure over the self parameter. This is convenient for the common
>> case of providing callbacks which are methods of some object.
>
> Definitely convenient.
>
> The other thing I find myself wanting is:
>
>        obj:[ method_expr ]( ... )
>
> as syntax for obj[ method_expr ]( obj, ... ).
>
> This is useful when you need to compute the method to invoke. It has the benefit of avoiding the need to make sure you stick obj into a local variable to avoid double-evaluation. It also opens up the possibility that at some point in the future, colon might become a "real" operator and not just syntactic sugar.
>
> This is actually easier to implement than obj:method as a way to create a closure since it mostly just takes as I recall some small parser revisions and a slight revision to OP_SELF.
>
> Mark
>
>
>

I often find myself wishing I could write:
foo:bar.baz(1, 2)
to mean:
foo.bar.baz(foo, 1, 2)

-- 
Sent from my toaster.