Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: MRAB Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Fri, 27 Nov 2015 02:56:12 +0000 Lines: 69 Message-ID: References: <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de ytmFKHUhOTntpF8TjkSHsAqWPecWxYwRQkTu8BNH6Aog== 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; 'compiler': 0.05; 'chunk': 0.07; 'exist,': 0.07; 'finished.': 0.07; 'pypy': 0.07; 'debugger': 0.09; 'exiting': 0.09; 'garbage': 0.09; 'high-level': 0.09; 'hooks': 0.09; 'object)': 0.09; 'objects:': 0.09; 'python': 0.10; 'thu,': 0.15; 'definition.': 0.16; 'expected,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'hex': 0.16; 'ironpython': 0.16; 'low-level': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'pypy.': 0.16; 'rather,': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'say)': 0.16; 'wrote:': 0.16; 'looked': 0.16; 'memory': 0.17; 'numerical': 0.18; 'refers': 0.18; 'say,': 0.18; '(in': 0.18; 'programmer': 0.18; 'language': 0.19; '>>>': 0.20; 'changes': 0.20; '2015': 0.20; 'location,': 0.22; 'object.': 0.22; 'struct': 0.22; 'suppose': 0.22; 'pass': 0.22; 'code.': 0.23; 'seems': 0.23; 'represents': 0.23; 'unlike': 0.23; 'header :In-Reply-To:1': 0.24; 'all.': 0.24; 'header:User-Agent:1': 0.26; 'sense': 0.26; 'compare': 0.27; 'fri,': 0.27; 'not.': 0.27; 'moved': 0.27; 'object,': 0.27; 'actual': 0.28; 'argue': 0.29; 'preserve': 0.29; 'array': 0.29; 'convert': 0.29; 'objects': 0.29; 'there.': 0.30; "i'm": 0.30; 'connection': 0.30; 'code': 0.30; 'received:84': 0.32; 'scanned': 0.32; "d'aprano": 0.33; 'steven': 0.33; 'editor': 0.34; 'that,': 0.34; 'list': 0.34; 'could': 0.35; 'exist': 0.35; 'list:': 0.35; 'nov': 0.35; 'but': 0.36; 'list,': 0.36; 'there': 0.36; 'actions': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'turn': 0.37; 'say': 0.37; 'creation': 0.38; "won't": 0.38; 'mean': 0.38; 'or,': 0.38; 'test': 0.39; 'sure': 0.39; 'expressed': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'identify': 0.61; 'here.': 0.62; 'course': 0.62; 'different': 0.63; 'guaranteed': 0.67; 'special': 0.73; '*every': 0.84; 'distinguish': 0.84; 'farrance': 0.84; 'snapshots': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=MbeRwMLf c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=IkcTkHD0fZMA:10 a=kZ7UWmmPAAAA:8 a=7VzW9X5Lxz-GggKrHWYA:9 a=6wXg-LdOnL9dVtqU:21 a=YpkecUAZH4T6N-Mr:21 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> 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: , Xref: csiph.com comp.lang.python:99622 On 2015-11-27 02:44, Steven D'Aprano wrote: > On Fri, 27 Nov 2015 12:40 pm, Ben Finney wrote: > >> Steven D'Aprano writes: >> >>> On Thu, 26 Nov 2015 09:34 pm, Dave Farrance wrote: >>> >>> >>> > (Conversely, I see that unlike CPython, all PyPy's numbers have >>> > unchanging ids, even after exiting PyPy and restarting, so it seems >>> > that PyPy's numerical ids are "faked".) >>> >>> I'm pretty sure that they are faked. >> >> It's still not been expressed what “fake” refers to here. Or, rather, >> what “real” thing was being expected, and how these don't qualify. > > They are faked in the sense that in this implementation, the object lifespan > that you think of as the Python programmer has little if any connection to > the actual lifespan of the chunk of memory representing that object. > > Suppose you have a Python object which in turn contains three other objects: > > L = [10001, 10002, 10003] > > Take the id of that list: > > myid = id(L) > > You do some long-running processing of that list, and then compare the id at > the end: > > assert myid == id(L) > > This is guaranteed to pass by the language definition. > > We can say that at *every instant* from the creation of the list to the > moment it is garbage collected, if you took a snap-shot of the process' > memory, and manually scanned through it, you could be able to identify four > object structs, corresponding to the list and the three ints. They might > move around and be found in different memory locations, (as in IronPython > and Jython), but they will be there. > > But not with PyPy. Not only might the objects have moved location, but in > some snapshots you won't find them at all. The JIT compiler may convert the > high-level Python objects (a list, and three ints) to (let's say) a > low-level array containing three C shorts, perform processing on that, and > then recreate the Python objects only when finished. > > Looked at from the perspective of the implementation, the actual lifespan of > the objects (in the sense of the struct in memory that represents that > object) may be much less than what we see from the perspective of the > high-level Python code. > > Of course in Python, the object continues to exist the whole time, as far as > we can tell -- there is no test we can do from Python code that can > distinguish the state of the object, just as there is no test we can do > from Python to tell whether an object has moved memory location or not. But > from outside of Python -- say, a debugger that hooks into the particular > implementation, or by taking a dump of the memory and looking at it in a > hex editor -- we can see the high-level objects come and go and move > around. > > The PyPy implementation has to take special actions to preserve the ID > across object recreations. That is what I mean by "faked". > You could argue that it _does_ continue to exist, it just changes its form...