anything like C++ references?

Stephen Horne intentionally at blank.co.uk
Tue Jul 15 05:34:01 CEST 2003


On Mon, 14 Jul 2003 17:06:17 -0700, Tom Plunket <tomas at fancy.org>
wrote:

>>>> a = 5
>>>> b = ref_to(5)
>>>> a = 3
>>>> print b
>3
>
>This would require a new built-in probably, and any time you
>(accidentally?) did 'b = c', then you'd lose that reference,
>but...  hmm, I wonder if it'd be handy.
>
>Probably not enough to justify the expense.  :)

True - but the problem doesn't arise if you need to explicitly
dereference pointers to access the objects they point to.

>>> a = 5
>>> b = &a
>>> a = 3
>>> *b
3
>>> *b = 7  #  note - not 'b = c'
>>> a
7

Providing the pointers aren't low level store addresses or fuzzy
concepts vaguely related to arrays as in C, the principle would work
just fine.





More information about the Python-list mailing list