Modifying Class Object

Alf P. Steinbach alfps at start.no
Sun Feb 14 19:41:10 EST 2010


* Ethan Furman:
> Steve Howell wrote:
>>
>> Going back to pointers vs. references, I think the key distinction
>> being made is that pointers allow specific memory manipulation,
>> although I think even there you're really just dealing with
>> abstractions.  The address 0x78F394D2 is a little bit closer to the
>> machine than, say, the 42nd element of a Python list, but they are
>> both just abstractions on top of underlying machines, whether the
>> machines are virtual, electronic circuits, vacuum tubes, whatever.
>> You can add 6 to 42 and get the 48th object, but its Python's
>> convention not to call the 48th object a memory address or expose a
>> reference to it as a pointer.  If I want to pass along the reference
>> to the 48th element of a list as the slot to be updated (i.e. with the
>> intention to actually mutate the list itself), then I need a tuple
>> like (lst, 48).
>>
> 
> I think that's the key right there -- if 48 was really a pointer, you 
> wouldn't need to pass lst in as 48 would in fact be the memory address 
> of the object you wanted to manipulate.

The generalization is known as a "based pointer".

Except where it's a fundamental abstraction in a programming language, where it 
might be called anything.

For example, in C++ some so called "member pointers" are logically based 
pointers. They have pointer syntax (as do C++ iterators, which are not 
necessarily pointers), but member pointers are not pointers in the C++ 
standard's sense; in particular, dereferencing a C++ member pointer yields a 
typeless entity, which is not the case for a normal pointer, although that 
standard confusingly calls also member pointers pointers in some places, and in 
other places uses the pointer term only about basic pointers.

So, delving into the details of that terminology means traveling into a pretty 
chaotic territory. But on the other hand, going for the more abstract it gets 
cleaner and simpler. The Wikipedia article is about in the middle somewhere.

It is perhaps not confusing that it is confusing to many. :-)


Cheers & hth.,

- Alf



More information about the Python-list mailing list