Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'operator': 0.03; 'compiler': 0.05; 'definitions': 0.07; 'executable': 0.07; 'expressions': 0.07; 'subject:skip:c 10': 0.07; '"run': 0.09; 'arg': 0.09; 'called.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'def': 0.10; 'distinction': 0.16; 'lambda': 0.16; 'message-id:@dough.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'statements,': 0.16; 'time"': 0.16; 'wrote:': 0.17; 'resolved': 0.17; 'jan': 0.18; '>>>': 0.18; 'define': 0.20; 'defined': 0.22; "i'd": 0.22; '15,': 0.23; 'statement': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'am,': 0.27; 'execution': 0.27; 'header:X -Complaints-To:1': 0.28; 'subject:list': 0.28; 'chris': 0.28; 'run': 0.28; "d'aprano": 0.29; 'statements': 0.29; 'steven': 0.29; 'objects': 0.29; 'points': 0.29; 'function': 0.30; 'function.': 0.33; 'to:addr:python-list': 0.33; 'times.': 0.33; 'received:org': 0.36; 'but': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'time,': 0.62; 'between': 0.63; 'necessarily': 0.63; 'different': 0.63; 'more': 0.63; 'jul': 0.65; 'treat': 0.65; 'bodies': 0.71; 'received:fios.verizon.net': 0.84; 'subject:funny': 0.91; 'time)': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: lambda in list comprehension acting funny Date: Sun, 15 Jul 2012 06:27:43 -0400 References: <03943ea6-5914-4de4-821c-055bed1d5804@f9g2000pbd.googlegroups.com> <4fffc1fd$0$29965$c3e8da3$5496439d@news.astraweb.com> <5000608c$0$6930$e4fe514c@news2.news.xs4all.nl> <500200be$0$29995$c3e8da3$5496439d@news.astraweb.com> <5002802f$0$29995$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: <5002802f$0$29995$c3e8da3$5496439d@news.astraweb.com> 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342348081 news.xs4all.nl 6861 [2001:888:2000:d::a6]:34736 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25345 On 7/15/2012 4:32 AM, Steven D'Aprano wrote: > On Sun, 15 Jul 2012 10:49:48 +1000, Chris Angelico wrote: > >> On Sun, Jul 15, 2012 at 9:29 AM, Steven D'Aprano >> wrote: >>> Not necessarily *compile* time, but the distinction is between when the >>> function is defined (which may at compile time, or it may be at run >>> time) versus when the function is called. >> >> I'd treat the def/lambda statement as "compile time" and the () operator >> as "run time". > > But function definitions occur at run time, not compile time -- they are > executable statements, not instructions to the compiler to define a > function. The () operator is 'call time'. The main points are a) the execution of def statements and lambda expressions and the execution of calls happen at different run times. b) default arg objects are calculated at def/lambda time. c) names in def bodies and lambda expressions are resolved at call time. and d) people more often forget c) when thinking about lambda expressions that for def statements. -- Terry Jan Reedy