Assignment operator?

Ante Bagaric abagaric_NOSPAM at rest-art.hr
Thu Apr 18 11:44:16 EDT 2002


> Obviously, immutables must implement augmented assignment by re-binding
the
> name to a new object, otherwise
>
> >>> a = 3
> >>> a += 2
> >>> a
> 5

Umm, indeed. Somehow I overlooked this problem...

> would not be possible.
> I think what you haven't understood is the update in-place semantics that
> mutable object implementations *may* choose to adopt. Otherwise you seem
to
> have it down pat.

Hmm, and the compiler doesn't know in advance what object a name references,
so it has no choice but to flag '+=' as rebinding operation even if it is
not
the case. It doesn't sound nice, but I admit there's no obvious alternative
that
comes to mind. This whole namespace and local/global issue has an aura of
'unfinishness' around it :)








More information about the Python-list mailing list