Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'python.': 0.02; 'causing': 0.04; 'emulate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'pointers,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; "python's": 0.19; 'print': 0.22; 'header :User-Agent:1': 0.23; 'either.': 0.24; 'compare': 0.26; 'pass': 0.26; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; "i'm": 0.30; 'workaround': 0.31; 'another': 0.32; 'url:python': 0.33; 'ago': 0.33; 'alone': 0.33; 'but': 0.35; 'there': 0.35; 'picking': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'url:01': 0.39; 'url:2012': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'days': 0.60; 'french': 0.61; "you're": 0.61; 'email addr:gmail.com': 0.63; 'name': 0.63; 'refer': 0.63; 'love': 0.65; 'linked': 0.65; 'deeply': 0.69; 'wish': 0.70; 'url:wordpress': 0.78; 'classic,': 0.84; 'pain': 0.84; 'tous': 0.84; 'you...': 0.96 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Closures in leu of pointers? Date: Sat, 29 Jun 2013 14:12:57 +0200 Organization: None References: <2a2072e3-4b12-4ada-872c-1240d2379928@googlegroups.com> <2603336f-e9d2-441a-8535-957d8fec2002@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p508485e6.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372507979 news.xs4all.nl 15937 [2001:888:2000:d::a6]:47738 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49414 cts.private.yahoo@gmail.com wrote: > As for python 3 ... "nonlocal"? I see I'm not alone in picking obnoxious > names ... tous chez... > Alas, one reason it's a weak workaround is that it doesn't work - at > least, not how I wish it would: > $ cat ptrs > > x = 34 > > def p1 (a1): > > a1[0] += 12 > > p1 ([x]) > > print (x) > > $ python ptrs > 34 That doesn't work with 'nonlocal' either. You can compare Python's names with (automatically dereferenced and garbage-collected) pointers, but there is no way to have a name refer to another name. The C-like f(var *value) { value = ... } is the only way to pass a variable in Python. There is no way to emulate f(var **value) { *value = ... } When this came up a few days ago I linked to http://learntofish.wordpress.com/2012/01/09/call-by-object-reference-call-by-sharing/ but I was actually looking for the classic, so there: http://python.net/~mwh/hacks/objectthink.html PS: If you're reading this and love the French language -- I am deeply sorry for the pain I'm causing you...