Pointers

Hrvoje Niksic hniksic at iskon.hr
Fri Mar 24 15:40:12 CET 2000


"David Robinow" <drobinow at dayton.adroit.com> writes:

> Curtis Jensen <cjensen at be-research.ucsd.edu> wrote in message
> news:38DA9F8C.E9133C71 at be-research.ucsd.edu...
> > Python does work on a reference setup, but it's not exactly like
> > pointers.  For example:
> > >>> a = 5
> > >>> b = a
> > >>> a = 3
> > >>> print b
> > 5
> >
> > If b were a pointer to b then print b would return 3, not 5.  There is
> > the problem of mutable types and immutable types here, but the same
> > thing occurs if you use a mutable type.  So, pointers and python
> > referances are not the same.
> 
> It's not clear how you get the above conclusion

By assuming that `=' modifies the objects pointed to by a and b
destructively.

I understand this confusion; I had similar problems when I started to
learn Lisp -- the difference between a SETQ and a destructive
modification to a cons deluded me for some time.

The crux of the matter is: a and b are not objects that point to
numbers; they are variables that refer (point) to numbers, which are
objects.  The operation `=' makes the variable point to a different
number object, as your C program demonstrates.



More information about the Python-list mailing list