anything like C++ references?

I V ivlenin at gmx.co.uk
Mon Jul 14 08:56:06 EDT 2003


On Sun, 13 Jul 2003 20:39:56 +0100, Stephen Horne
<intentionally at blank.co.uk> wrote:

>The fact is that 'assignment' has a common meaning separate from the
>choice of programming language, and that the way Python handles name

Yes.

>binding means that meaning is not respected by Python for mutable
>objects.

No.

Assignment takes a name and binds it to a different value, whatever
programming language you use. Python does this for both immutable and
mutable types. The same is true of Lisp, and of C++ (although, in C++,
you can provide an implementation of operator= which does something
else, just as you can provide an implementation of operator+ which
doesn't add, but in both cases to do so is a mistake).

>Python, however, does not respect this meaning. It uses an arbitrary
>distinction based on whether or not the object has internals that can
>be usefully in-place modified, and uses that distinction to vary the

No, it doesn't. 

x = (1, 2) 

binds the name 'x' to a tuple entity with the value '(1, 2)'. 

x = [1, 2]

binds the name 'x' to a list entity with the value '[1, 2]'.

There's no distinction here, arbitary or otherwise. There is an
exposed implementation detail as regards the identity of immutable and
mutable entities, but this doesn't effect the semantics of their
values.
-- 
"Mr I V Lenin, the Lenin of love"




More information about the Python-list mailing list