Overloadable Assignment PEP
Christopher A. Craig
list-python at ccraig.org
Fri Apr 4 10:51:47 EST 2003
drew at astro.pas.rochester.edu (Drew Moore) writes:
> so far, the response seems to be:
> "it is technically possible, but my scripts might
> run slower.. and it just makes me nervous."
Not might run slower, would run not just slower but a ton slower.
You're basically replacing the C code
a=b
with at least one, and possibly several dict lookups. Your idea about
caching the value is a decent one, but you have the problem that class
dicts are mutable, so what if someone does
>>> class foo:
... pass
...
>>> t = foo()
>>> t.__dict__.__assign__ = lambda t, a: t.elem=a
If __assign__ is allowed, that will be expected to work.
A bigger problem to me is that '=' currently means rebinding names.
If I see 'a=b' in Python, I immediately presume that 'a' doesn't exist
after the assignment. If you change this then it will sometimes mean
rebinding and sometimes mean something else.
If you want a way to set something's value, I imagine you'll have a
lot more support for adding an operator rather than making '=' one.
I'm all for Lulu's suggestion of adding a ':=' operator for that sort
of situation.
--
Christopher A. Craig <list-python at ccraig.org>
"The world would be a better place if Larry Wall had been born in Iceland,
or any other country where the native language actually has syntax."
-- Peter da Silva (in alt.sysadmin.recovery)
More information about the Python-list
mailing list