Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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; 'assign': 0.04; 'function,': 0.07; 'python': 0.08; 'decorator': 0.09; 'encouraged.': 0.09; 'initialized': 0.09; 'parameter.': 0.09; 'rename': 0.09; 'am,': 0.12; 'def': 0.13; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'subject:was': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda': 0.16; 'lookup': 0.16; 'subject:=': 0.16; 'subject:Early': 0.16; 'language': 0.17; 'wrote:': 0.18; '>>>': 0.18; 'maybe': 0.21; 'dec': 0.22; "doesn't": 0.22; 'header:In- Reply-To:1': 0.22; "python's": 0.24; 'static': 0.24; 'sat,': 0.25; 'function': 0.27; '(you': 0.28; 'message-id:@mail.gmail.com': 0.28; '24,': 0.29; 'feature,': 0.30; "it'd": 0.30; 'recursion': 0.30; 'yes.': 0.30; 'value.': 0.32; 'subject:]': 0.32; 'that,': 0.33; 'to:addr:python-list': 0.34; 'assignment': 0.34; 'function.': 0.34; 'variables': 0.37; 'skip:" 10': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'steven': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'help': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'might': 0.40; '2011': 0.61; 'benefit': 0.69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=7BjB13rp7VkOMb0DkAuZaWwr2vrPzRhrs++93BdK7q4=; b=mq1FPTlglPduxVMD/AcsBFqk8iP68ptFZMVndewCFLXA7A7dqpS01VkU84rdKgIFEy 2re9l95wvWwxKO97TWSBQmPB8AaLDF/s0qXIKq+9qt7ZHVQ4cMnYewI4bt8HfSb3zy4Y FiY/5wuSRTGtbU6ziGUys1qFoUpKAOMKgeTzY= MIME-Version: 1.0 In-Reply-To: <4ef5016e$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <18f78d0d-1e70-4c7b-9033-1422e6edb6db@t13g2000yqg.googlegroups.com> <10c62dac-2750-4f08-8962-21952c1c0a0b@v31g2000prg.googlegroups.com> <5a7a7aab-a320-4429-a130-ffcfcf0ac174@v24g2000prn.googlegroups.com> <4EF440A9.7030101@stoneleaf.us> <9ljcutFemiU5@mid.individual.net> <9ljd41Fp3bU1@mid.individual.net> <4ef4a30d$0$29973$c3e8da3$5496439d@news.astraweb.com> <4ef5016e$0$29973$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 24 Dec 2011 09:50:04 +1100 Subject: Re: Early and late binding [was Re: what does 'a=b=c=[]' do] From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324680607 news.xs4all.nl 6857 [2001:888:2000:d::a6]:44317 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17829 On Sat, Dec 24, 2011 at 9:32 AM, Steven D'Aprano wrote: > Yes. But having to manage it *by hand* is still unclean: Well, my point was that Python's current behaviour _is_ that. > * you still have to assign the default value to the function assignment > outside the function, which is inelegant; C's static variables are initialized inside the function. But since Python doesn't have that, it doesn't really work that way. (You might be able to use a decorator to do some cool tricks though.) > * if you rename the function, the internal lookup func.default_value will > fail. Python would benefit some from a "current-function" reference, if tricks like this were to be encouraged. It'd help with recursion too. hmmmm... >>> def Y(func): return lambda *args,**kwargs: func(func,*args,**kwargs) >>> @Y def foo(me,x): if x>5: return x return me(me,x+1),7,x >>> foo(3) (((6, 7, 5), 7, 4), 7, 3) Useful? Not very. Maybe as a language feature, but not as a parameter. But of curiosity value. ChrisA