lua-users home
lua-l archive

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

On Wed, Jan 26, 2011 at 5:36 PM, Guy Banay <> wrote:
> Since foo:bar() is equivalent to , I expected the following code:
> f = foo:bar
> To do something along the lines of:
> f = (function(self) return function() return self:bar() end end)(foo)
> In other words, I expect foo:bar to return a function. Is there any
> reason why it shouldn't do this?

If method calls are used at all in a piece of Lua code, then they are
generally used quite a lot. Your proposed behaviour of foo:bar (with
proper forwarding of all arguments) would give the specified behaviour
of "foo:bar(...) ==, ...)", but at the cost of creating a
closure for every single method call, which would be horribly
inefficient when method calls are used a lot. Fine you say, how about
keeping the current efficient implementation of "foo:bar(...)", and
only create a closure in the case of "foo:bar" not followed by an
argument list, but this is ugly from a language design point of view,
as then "foo:bar(...)" becomes a special-case of redefining the
semantics of something which is already valid syntax.