Terminology: "reference" versus "pointer"

Random832 random832 at fastmail.com
Sat Sep 12 23:27:51 CEST 2015


Akira Li <4kir4.1i at gmail.com> writes:
>Rustom Mody <rustompmody at gmail.com> writes:
>> viz. I have two variables (or names!) say a and b which look the same
>>>>> a
>> [[1,2],[1,2]]
>>>>> b
>> [[1,2],[1,2]]
>> And yet doing
>>>>> a[0][0] = "Oops!"
>> gives a data structure one "Oops!"
>> whereas doing it to b mysteriously gives 2
>
> Sorry, I haven't followed the whole thread. Could your provide a
> complete code example? Mention what you expect to happen and what
> happens instead in your case.

a0 = a1 = [1, 2]
b0 = [1, 2]
b1 = [1, 2]
a = [a0, a1]
b = [b0, b1]
del a0, a1, b0, b1

There's nothing about *him* expecting anything wrong to happen. The
question is how to draw a diagram that unambiguously shows the resulting
structure using the "parcel tags" model shown in the diagrams (and
without having a0/a1/etc as actual names)

It's easy to draw such a diagram for the "boxes and arrows" model:

(@ shows the box named by a[0][0]. Or a[1][0].)

a[*]-->[*]----v       
       [*]-->[@]--------->(1)
             [*]-.        ^^
                 `--------++--.
b[*]-->[*]-->[*]----------'|  |
       [*]-. [*]-----------+-.|
           v               | ||
          [*]--------------' vv
          [*]--------------->(2)

If the "parcel tags" model can't show it, then the "parcel tag" model
clearly is not a correct and complete depiction of how Python actually
works.

(If I were drawing a picture rather than ASCII I'd add something to make
it clear that the pairs shown are list objects Like, it's a circle with
the word "list" and two pointer-boxes inside it.)



More information about the Python-list mailing list