Terminology: "reference" versus "pointer"

Steven D'Aprano steve at pearwood.info
Mon Sep 14 12:59:36 EDT 2015


On Mon, 14 Sep 2015 01:23 pm, Akira Li wrote:

> Steven D'Aprano <steve at pearwood.info> writes:
> 
>> On Mon, 14 Sep 2015 11:22 am, Akira Li wrote:
>>> Look at the last example:
>>> http://thread.gmane.org/gmane.comp.python.general/782626/focus=782704
>>
>>
>> I'm afraid that page is broken in my browser. Can you not summarise, or
>> link to the specific message? I may be able to use another browser in a
>> day or two, but hopefully the discussion will have moved on by then.
> 
> https://mail.python.org/pipermail/python-list/2015-September/696631.html

Thanks. You mean this example?

  lst = [range(1, 3) for _ in range(3)]
  a = [lst[0], lst[0]]
  b = [lst[1], lst[2]]


I don't see what's difficult about this example. Here's a simple ASCII
drawing:


lst --------> [ range-object-1 , range-object-2 , range-object-3 ]

a ----------> [ range-object-1 , range-object-1 ]

b ----------> [ range-object-2 , range-object-3 ]



Trying to draw an arrow diagram using text is not my idea of a good time,
but I'll give it a go. Requires a monospaced font and an email client that
won't reflow the text:

      +-----+------+
      |     |      | <--------------------------- a
      +--|--+---|--+
         |      |
         |      |
         V      |
      +-----+ <-+             +----+
      |range| <---------------|-   |<------------ lst 
      +-----+                 +----+
                  +-----------|-   |
      +-----+     |           +----+
  +-> |range| <---+    +------|-   |
  |   +-----+          |      +----+
  |                    |
  |   +-----+          |
  |   |range| <--------+
  |   +-----+
  |      ^
+-|-+    |
|   |    |
+---+    |
|  -|----+
+---+
  ^
  |
  +------------------------------------------- b



Out of the two, I know which one I prefer.



-- 
Steven




More information about the Python-list mailing list