Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.87.MISMATCH!newsfeed.xs4all.nl!newsfeed1.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.001 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; 'sentence': 0.09; 'subject:while': 0.09; 'python': 0.11; 'template': 0.14; '(1,': 0.16; 'compiler.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'immutable,': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reedy': 0.16; 'subject:recursion': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'items.': 0.19; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'copied': 0.24; 'developers': 0.25; 'compiled': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; '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; 'received:84': 0.35; 'but': 0.35; 'next': 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; 'analyze': 0.60; 'dave': 0.60; 'is.': 0.60; 'first': 0.61; 'here': 0.66; 'header :Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'conservative': 0.84; 'reply-to:addr:python.org': 0.84; 'angel': 0.91; 'not:': 0.91; '2013': 0.98 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=PIY2p5aC c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=LqG8EI-UCiYA:10 a=DVkrMzQw-UUA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=ZPwmbRZxN1IA:10 a=VdKeiqsKSM6QqZAogRsA:9 a=wPNLvfGTeEIA:10 X-AUTH: mrabarnett:2500 Date: Thu, 03 Oct 2013 02:46:53 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Tail recursion to while iteration in 2 easy steps References: <87had0axxy.fsf@dpt-info.u-strasbg.fr> <524cc73a$0$29984$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380764808 news.xs4all.nl 15902 [2001:888:2000:d::a6]:41018 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55397 On 03/10/2013 02:39, Dave Angel wrote: > 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. > The key point here is that the tuple is immutable, including its items.