[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: New metamethod for method lookup
- From: Florian Weimer <fw@...>
- Date: Sat, 21 Nov 2009 12:40:25 +0100
* steve donovan:
> On Mon, Nov 16, 2009 at 1:13 AM, TNHarris <firstname.lastname@example.org> wrote:
>> What about dot syntax?. I'd expect set.intersection to not be the same
>> thing as set['intersection'] in the object you describe.
> But any Lua programmer does expect this equivalence, it's as basic as
> p[i] == *(p + i) in C.
Except that most C programmers are surprised by this---and that they
can actually write i[p], too. 8-)
I think Lua's uniform lookup rules have their issues (as pointed out
in this thread, adding methods to objects which support arbitrary keys
for indexing is not possible, for instance). But as an advantage, it
is possible to actually describe the lookup rules. I have yet to find
such a description for Python's attribute lookup rules (those
complexities do not come from the key/attribute distinction
exclusively, but I guess one thing led to another, and now the whole
thing is quite impenetrable). I'm not saying that Python's data model
is bad; you can write some constructs very concisely and clearly, but
at the cost of a rather complex (and slow) underlying lookup process.