Another try at Python's selfishness

Antoon Pardon apardon at forel.vub.ac.be
Fri Feb 3 09:53:12 EST 2006


Op 2006-02-03, Ben Sizer schreef <kylotan at gmail.com>:
>
> n.estner at gmx.de wrote:
>> The main reason (at least for me) is that there's simply too much
>> "magic" in it. Why does the expression left of the '.' get promoted to
>> the first parameter?
>
> One of the reasons I like Lua is because it doesn't do this, instead
> using the : operator to designate method-style calls.
>
> eg.
> a:foo(b, c) -- looks up foo within a, and calls it with (a, b, c) as
> parameters
> a.foo(b, c) -- looks up foo within a, and calls it with (b,c) as
> parameters
>
> This means there doesn't need to be a distinction between methods and
> functions, just a different operator to treat a function as if it was a
> method.

That is nice. I wonder if the following is possible in Lua:

  fun = a:foo
  fun(b, c)

with the same effect as:

  a:foo(b, c)

-- 
Antoon Pardon



More information about the Python-list mailing list