Another try at Python's selfishness

Ben Sizer kylotan at gmail.com
Fri Feb 3 09:02:13 EST 2006


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.

When I started out in Python I figured that I could just assign
functions to objects and treat them then as if they were methods, as I
would in Lua, but quickly learned that it wasn't that simple.

-- 
Ben Sizer




More information about the Python-list mailing list