Terminology: “reference” versus “pointer”

Random832 random832 at fastmail.com
Sat Sep 12 01:42:43 EDT 2015


Ben Finney <ben+python at benfinney.id.au> writes:
> The reference value is inaccessible to the program, it can only be used
> to get at the referenced object.

That's like saying an integer is inaccessible since it can only be used
to add/subtract/etc (list of all operations you can do with an
integer). What does it mean to access something, if not to do some
operation on it? Getting the referenced object is the operation you can
do with it.

>> > 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.

So, if you have a list x, and assign a new value to x[0], it doesn't
change the list, because you can't compare the list to the value the
list had before?

You're not making any sense. It's a value. Changing it and "throwing
away and replacing with a different one" are the same thing.

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

I don't understand what you mean by "can never again get at" it if you
think you _can_ do it for mutable values.

>> > 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
> reference.

Yes it is. I don't know why you think it's not, so I can't even figure
out how to respond to this.




More information about the Python-list mailing list