[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Sugar for obj:method as a closure (was First Class ':')
- From: steve donovan <steve.j.donovan@...>
- Date: Fri, 15 Jan 2010 15:05:24 +0200
I seem to have got the idea that this was originally a Mark H
proposal, but he was just a supporter (by his own admission)
The idea is that 'obj:method' (without parenthesis) is sugar for the
closure 'function(...) return obj:method(...) end', so that you can
bind methods to a particular object (rather as how C++ Builder
considered as '__closure' in its extensions to the language)
It isn't as ambiguous as one might think, in fact it resolves an ambiguity:
> s = 'hello'
> fn = s:find
stdin:2: ambiguous syntax (function call x new statement) near '('
(This is one of the few cases where newlines will mess with the Lua parser)
It definitely was considered in Rio. Luiz rules out another
overloading of obj:method on these grounds in , although Roberto
presents a simple Lua function to do this in  (and jokes that it
should work in other cities as well.)
And then froese comes back with a concrete proposal .
Any further thoughts about this rather useful construct?