Terminology: “reference” versus “pointer”

Ben Finney ben+python at benfinney.id.au
Sat Sep 12 07:20:51 CEST 2015

Random832 <random832 at fastmail.com> writes:

> Ben Finney <ben+python at benfinney.id.au> writes:
> > Random832 <random832 at fastmail.com> writes:
> >
> >> Ben Finney <ben+python at benfinney.id.au> writes:
> >> > With the significant difference that “pointer” implies that it has its
> >> > own value accessible directly by the running program, such as a pointer
> >> > in C.
> >>
> >> Its own value *is* what you're accessing when you assign or return it.
> >
> > You're not describing Python references.
> Yes I am. You're just making the implicit assumption that a "value" has
> to be a number, and I was ignoring that assumption. The value is the
> address of an object. Like I said, an arrow on a diagram.

I made no assumption about the type; I don't care how the reference is
implemented in the Python interpreter. That's not accessible to the
running Python program without some API.

My assertion still stands: the address of the object is *not* what the
reference is, in Python. Calling ‘id(foo)’ does not return a reference
to ‘foo’, so I don't know how you think the value is accessible in the
Python program.

The reference value is inaccessible to the program, it can only be used
to get at the referenced object.

> > So in Python, we don't have pointers because we don't have access to
> > change or reassign them.
> Yes you do. That's _exactly what happens_ in an assignment statement -
> you are reassigning it to the address of another object. And that's
> something you *can't do* with references in C++.

The operation you describe doesn't change the reference; it doesn't
mutate an existing value which can be compared with whatever value it
had before. Instead, it throws away one reference and replaces it with a
different one.

That's significant, because unlike a mutable value you can never again
get at the old reference in the Python program.

> > You can't, for example, keep the old reference (there are no references
> > to references in Python), because they're not accessible as values in
> > themselves. Once you assign a different reference, the old one is gone
> > and can't be found again.
> You can keep it by copying it to somewhere.

How do you propose to “copy” a reference in Python? Making a new
reference to the referenced object is not making a copy of the

 \     “Demagogue: One who preaches doctrines he knows to be untrue to |
  `\                     men he knows to be idiots.” —Henry L. Mencken |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list