X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 78.192.65.63 Path: csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!news.muarf.org!news.roellig-ltd.de!open-news-network.org!border2.nntp.ams1.giganews.com!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'value,': 0.04; 'model,': 0.05; '*not*': 0.07; 'memory.': 0.07; 'referring': 0.07; 'transform': 0.07; 'explanation': 0.09; 'pointers': 0.09; 'references,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"python': 0.16; 'behaviour.': 0.16; 'chris,': 0.16; 'cons': 0.16; 'elements,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lisp': 0.16; 'objects.': 0.16; 'play.': 0.16; 'pointers,': 0.16; 'semantics': 0.16; 'storing': 0.16; 'subscripting': 0.16; 'variable.': 0.16; 'prevent': 0.16; ':-)': 0.16; 'wrote:': 0.18; '(but': 0.19; 'pointed': 0.19; "python's": 0.19; 'value.': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'either.': 0.24; 'integer': 0.24; 'pointer': 0.24; 'cc:2**0': 0.24; 'references': 0.26; 'pass': 0.26; 'post': 0.26; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; 'function': 0.29; 'specifically': 0.29; 'chris': 0.29; "doesn't": 0.30; 'said,': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; "d'aprano": 0.31; 'helpful.': 0.31; 'pascal': 0.31; 'steven': 0.31; 'another': 0.32; 'programmers': 0.33; 'subject:time': 0.33; 'copying': 0.34; 'sense': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'fun,': 0.36; 'similar': 0.36; 'example,': 0.37; 'virtual': 0.37; 'being': 0.38; 'sometimes': 0.38; 'pm,': 0.38; 'rather': 0.38; 'anything': 0.39; 'explain': 0.39; 'itself': 0.39; 'though,': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'even': 0.60; 'most': 0.60; 'simply': 0.61; "you're": 0.61; 'first': 0.61; 'different': 0.65; 'talking': 0.65; 'between': 0.67; 'it!': 0.67; 'equals': 0.68; 'fact,': 0.69; '2015': 0.84; 'hardly': 0.84; 'to:none': 0.92; 'differences': 0.93 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=WzOFX455vbzK899TU9HkGff1EYxm45/FRPdgT+Gc5So=; b=N5aipTJ+MF1TVjSprP08TNtGT9yoRCKbBJQ3bRA3+Z+yjXGvp3ssBU3ZD6Ns/Q6HHP vUz1OOlzymkCccP21XfKamxZDyHp04Re4ZLHmyOmI1oG7z+yMk93IzRjBg9d2Z+canFO p2pXVXs/zVPp6RG9tvKSNOOqMOR7Wy2cNBU8qQzEbSFKXQHkSfqUeQnTCuiYJvVXPxNZ oLpy/Kdynsm7zaYHhTQP9yMdHtwYPnIXgEXcAIlrfiDeZCWjzxxHG2585PlIia/QccL4 UTruTTCPF+zib8rrIQWBcMGgCHYmSrYL7ksAeVLoY3A14JJSNvEO0nsGPSt+dEwx6jQt 0EBQ== MIME-Version: 1.0 X-Received: by 10.107.134.153 with SMTP id q25mr21687307ioi.27.1432041887940; Tue, 19 May 2015 06:24:47 -0700 (PDT) In-Reply-To: <555b2fa9$0$12996$c3e8da3$5496439d@news.astraweb.com> References: <9ceklad15llnv3npejq9iuh91soci8aeqo@4ax.com> <7ea01590-a559-46e5-abf5-29622e39aae7@googlegroups.com> <555ac697$0$12910$c3e8da3$5496439d@news.astraweb.com> <862693ca-42cf-4f5b-ac12-133e43e7606b@googlegroups.com> <878uclf3bt.fsf@elektro.pacujo.net> <555af171$0$12995$c3e8da3$5496439d@news.astraweb.com> <874mn9ezaw.fsf@elektro.pacujo.net> <555b2fa9$0$12996$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 19 May 2015 23:24:47 +1000 Subject: Re: Slices time complexity 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432041891 news.xs4all.nl 2905 [2001:888:2000:d::a6]:55142 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90849 On Tue, May 19, 2015 at 10:42 PM, Steven D'Aprano wrote: > On Tue, 19 May 2015 06:50 pm, Chris Angelico wrote: > >> On Tue, May 19, 2015 at 6:39 PM, Marko Rauhamaa wrote: >>> For example, you could explain Python's object references as pointers >>> (memory addresses) if you considered that helpful. (That's how Lisp >>> textbooks often explain cons cells.) >> >> Sorta-kinda-maybe, but if a C programmer's idea of pointers is invoked >> to explain Python's object references, the differences will start to >> be problematic: >> >> 1) Pointer arithmetic simply doesn't exist in Python. Arrays/lists are >> not just pointers to their first elements, and subscripting is most >> definitely NOT "add to pointer and dereference". >> 2) In fact, dereferencing as a whole isn't really a 'thing' either. At >> best, it happens automatically. >> 3) References actually mean something. Copying a pointer doesn't. >> Whether the Python you're using is refcounted (CPython) or >> mark-and-sweep (uPy, I think) or some other model, an additional >> reference to the same object will prevent it from being disposed of, >> which isn't the case in C. >> 4) A pointer is itself a value. You can pass a >> pointer-to-local-variable to another function and have that function >> change a local variable. >> 5) Furthermore, since a pointer is a value, you can have pointers to >> pointers, etc. Doesn't make any sense in Python. > > Chris, that is one of the best explanations for why "references equals > pointers" is *not* a good explanation for Python's behaviour. I may have to > steal it :-) :) They say that turnabout is fair play. I stole your "Python vs MATLAB" python-tutor post about call-by-value vs call-by-reference vs object semantics for years (until some other pages picked up the same content). Go for it! That said, though, I was specifically referring to C's pointer semantics. As Gregory pointed out, Pascal has rather different pointer semantics; but if you're talking about Python references and considering using any concept of object addressing and pointers, it's most likely going to be something similar to C/assembly, where a pointer is a dereferenceable integer storing an offset into memory. (But don't even get *started* on near vs far pointers, code vs data segments and the thunks required to transform between them, memory-mapped disk, virtual segments, overlapping segments, shared memory, memory-mapped I/O, and all those other things that C programmers sometimes contend with. Fun, but hardly anything to do with Python objects. :) ) ChrisA