anything like C++ references?
Martin v. Löwis
martin at v.loewis.de
Mon Jul 14 07:25:31 CEST 2003
Stephen Horne <intentionally at blank.co.uk> writes:
> >>>> a = ref(1)
> >>>> b = a
> >>>> a = 5
> >>>> b
> Well, during the 'debate', that's the basic idea that involved -
> except that I'd use explicit pointer-dereferencing syntax.
This is a very bad idea. You want to create a reference to the object
1? Then I assume that assigning to "a" would *change* the value of 1?
But 1 is an immutable object, it cannot change!
> Imagine, for instance, changing all assignments and other 'copying' to
> use a copy-on-write system.
That assumes that there is the notion of copying values in the first
place. Objects, in general, don't support copying - and assignment has
nothing to do with copying.
> >>> a = &5
> >>> b = newcopyof a # could be "b = &(*a)" in principle
> >>> *b is *a
Again, objects don't support copying. For immutable objects (like
numbers), copying is also a pointless operation: If there where a
standard .copy method on objects, numbers would return themselves.
There is no way, in the language, to express that you want different
copies of the value 5. This is completely different from the notion of
values in C or C++, where each occurrence of the literal 5 creates a
new value whose state is 5.
More information about the Python-list