Path: csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'objects,': 0.07; 'cc:addr :python-list': 0.09; 'collections': 0.09; 'definition,': 0.09; 'finite': 0.09; 'lst': 0.09; 'must,': 0.09; 'objects.': 0.09; 'python': 0.10; 'index': 0.13; 'def': 0.13; 'explicitly': 0.15; 'characters:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'infinity': 0.16; 'integers,': 0.16; 'len(self)': 0.16; 'numpy': 0.16; 'objects;': 0.16; 'pairs': 0.16; 'retrieving': 0.16; 'subject:reference': 0.16; 'subject:versus': 0.16; 'wrote:': 0.16; 'obviously': 0.16; 'drawing': 0.18; 'integer': 0.18; 'odd': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'arrays': 0.22; 'ascii': 0.22; 'sep': 0.22; 'programming': 0.22; 'am,': 0.23; 'code.': 0.23; 'bit': 0.23; 'needed.': 0.23; "python's": 0.23; 'references': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "doesn't": 0.26; 'define': 0.27; 'message-id:@mail.gmail.com': 0.27; '14,': 0.27; 'object,': 0.27; 'be:': 0.29; 'referenced': 0.29; 'styles': 0.29; 'sure,': 0.29; 'objects': 0.29; 'raise': 0.29; "we're": 0.30; 'skip:[ 10': 0.31; "i'd": 0.31; "can't": 0.32; 'skip:_ 10': 0.32; 'functional': 0.32; 'getting': 0.33; 'class': 0.33; 'add': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'clear': 0.35; 'exist': 0.35; 'false': 0.35; 'set.': 0.35; 'unicode': 0.35; 'something': 0.35; 'but': 0.36; 'instead': 0.36; 'there': 0.36; 'possible': 0.36; 'subject:" ': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'expect': 0.37; 'list.': 0.37; 'things': 0.38; 'creation': 0.38; 'stuff': 0.38; 'anything': 0.38; 'rather': 0.39; 'some': 0.40; 'collection': 0.60; 'more': 0.63; 'circle': 0.66; "they're": 0.66; 'note:': 0.66; 'results': 0.66; 'therefore': 0.67; 'picture': 0.70; 'chrisa': 0.84; 'construct': 0.84; 'ram,': 0.84; 'to:none': 0.91; 'different.': 0.91; 'lists:': 0.91; 'same,': 0.91; 'imagine': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=alc7f2XlMlbr1PS794vRowGX9VY/OczoBTt9Rc5ZZqM=; b=SxNPLUcRjB9jxkgwZ9cXdHSz/8i0Gw6ENEmXhFjPr4rlb0+aUjwzC7EDUXKwGHUC6g a1vHI2p688zJoAbpOBdBdNUJh4QwXkMPfc7YnJuBxC2SSMEuSWXSUAy5ncy33dkeHMqs PupH/3/bc/UmAvf9KP8R89tWmN8LWLfxg5Wn5z2VtvpNicRbXG8L0wA0chHjgYWiT3DQ XyqO8L+ZgJAOmFnmkMjnSXhxXsas2cpDXw0t1mcilHJo2lv0A6v5wTNXY9tTPaTBa5v7 MM7bp+YkCNYWcVmL6iKnj5ssFPw/rGd/0bq4FCwp4gHnrUnS5itCQDl9hGnANa/Xidlr 34yw== MIME-Version: 1.0 X-Received: by 10.107.132.144 with SMTP id o16mr18725534ioi.31.1442171039699; Sun, 13 Sep 2015 12:03:59 -0700 (PDT) In-Reply-To: <87wpvu5h7f.fsf@gmail.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> Date: Mon, 14 Sep 2015 05:03:59 +1000 Subject: Re: Terminology: "reference" versus "pointer" From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 70 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442171042 news.xs4all.nl 23732 [2001:888:2000:d::a6]:42619 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96518 On Mon, Sep 14, 2015 at 4:04 AM, Akira Li <4kir4.1i@gmail.com> wrote: >> (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.) > > "correct and complete" is impossible in the general case for any model. > > Imagine what happens if numpy arrays are used instead of Python lists: > > lst = [numpy.array([1, 2]) for _ in range(3)] > a = [lst[0], lst[0]] > b = [lst[1], lst[2]] > > Note: there could be no a[0][0], a[0][1], etc corresponding Python > objects until you explicitly reference them in the code. If there are no > Python objects then you can't draw any arrows and therefore "box and > arrows" model is incomplete. > > Or consider this collections of all Unicode characters: > > class U: > def __len__(self): > return sys.maxunicode + 1 > def __getitem__(self, index): > if index < 0: > index += len(self) > if 0 <= index < len(self): > return chr(index) > raise IndexError(index) > > u = U() > print(u[0x61]) # -> a > > In this example, it is even more clear that the corresponding items > might not exist until they are explicitly referenced in a program. What you've shown there is that it's perfectly possible to have an abstract collection which generates objects as they're needed. In the same way, you could define an infinite range object, which effectively has all positive odd numbers in it: class Odd: def __getitem__(self, index): if index >= 0: return index * 2 + 1 raise IndexError(index) Obviously it can't have objects representing every positive odd number, because that's an infinite set. If you want to think of this as containing all of those integers, sure, but now we're getting into functional programming styles and ways of representing infinity in finite RAM, and some things will look a bit different. However, none of this has anything to do with Python's object model. The expression "index * 2 + 1" results in the creation of new integer objects as required, rather than simply retrieving them from some containment list. The boxes-and-arrows stuff is all about pre-existing objects; if I construct one list from another, I expect all the references to be the same, but if I construct two Odd() objects, they don't have to be: >>> o1 = Odd(); x1 = o1[12345] >>> o2 = Odd(); x2 = o2[12345] >>> x1 is x2 False Even though every Odd() must, by definition, contain the exact same integers, it doesn't contain the same objects - it doesn't contain any objects. ChrisA