Path: csiph.com!eeepc.pasdenom.info!usenet.pasdenom.info!gegeweb.org!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.139.MISMATCH!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3.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; 'cpython': 0.05; "'',": 0.07; 'correct.': 0.07; 'made.': 0.07; 'referring': 0.07; '3),': 0.09; '[1,': 0.09; 'compile-time': 0.09; 'literal': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sentence': 0.09; 'subject:while': 0.09; 'python': 0.11; 'template': 0.14; '(1,': 0.16; 'compiler.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:recursion': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'copied': 0.24; 'developers': 0.25; 'compiled': 0.26; 'gets': 0.27; 'header:X -Complaints-To:1': 0.27; 'that.': 0.31; 'context,': 0.31; 'context.': 0.31; "d'aprano": 0.31; 'object.': 0.31; 'steven': 0.31; 'tuples': 0.31; 'quite': 0.32; 'sense': 0.34; 'core': 0.34; 'created': 0.35; 'but': 0.35; 'next': 0.36; 'charset:us-ascii': 0.36; 'two': 0.37; 'list': 0.37; 'lists.': 0.38; 'to:addr:python- list': 0.38; 'list,': 0.38; 'does': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'analyze': 0.60; 'is.': 0.60; 'first': 0.61; 'conservative': 0.84; 'not:': 0.91; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Tail recursion to while iteration in 2 easy steps Date: Thu, 3 Oct 2013 01:39:24 +0000 (UTC) References: <87had0axxy.fsf@dpt-info.u-strasbg.fr> <524cc73a$0$29984$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 174.32.174.31 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380764387 news.xs4all.nl 15943 [2001:888:2000:d::a6]:34914 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55396 On 2/10/2013 21:24, Steven D'Aprano wrote: > On Wed, 02 Oct 2013 18:17:06 -0400, Terry Reedy wrote: > >> CPython core developers have be very conservative about what >> tranformations they put into the compiler. (1,2,3) can always be >> compiled as a constant, and so it is. [1,2,3] might or might not be a >> constant, depending on the context, and no attempt is made to analyze >> that. > > The first sentence of this is correct. The next two don't quite make > sense to me, since I don't understand what you mean by "constant" in this > context. I *think* you might be referring to the LOAD_CONST byte-code, > which in Python 3.3 understands tuples like (1, 2, 3), but not lists. So > a literal (1, 2, 3) gets created at compile-time with a single LOAD_CONST > call: > > py> from dis import dis > py> dis(compile("x = (1, 2, 3)", '', 'exec')) > 1 0 LOAD_CONST 4 ((1, 2, 3)) > 3 STORE_NAME 0 (x) > 6 LOAD_CONST 3 (None) > 9 RETURN_VALUE > > > while a literal [1, 2, 3] does not: > > The difference is that a tuple can be reused, so it makes sense for the comiler to produce it as a const. (Much like the interning of small integers) The list, however, would always have to be copied from the compile-time object. So that object itself would be a phantom, used only as the template with which the list is to be made. -- DaveA