Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'calls.': 0.07; 'undefined': 0.07; 'cc:addr:python-list': 0.09; 'it;': 0.09; 'of)': 0.09; 'python': 0.10; 'python.': 0.11; 'wed,': 0.15; 'behaviour.': 0.16; 'folding': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'made,': 0.16; 'way;': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'constant': 0.22; 'programming': 0.22; 'am,': 0.23; 'thus': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; 'executing': 0.27; 'behaviour': 0.29; 'tail': 0.29; 'url:wikipedia': 0.29; "i'm": 0.30; 'subject:/': 0.30; 'url:wiki': 0.30; 'code': 0.30; '15,': 0.30; 'convention': 0.30; 'certain': 0.31; "can't": 0.32; '[1]': 0.32; 'functional': 0.32; 'language.': 0.32; 'options': 0.33; "d'aprano": 0.33; 'optimize': 0.33; 'steven': 0.33; 'that,': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'there': 0.36; 'url:org': 0.36; 'beginning': 0.36; 'depends': 0.36; 'subject:: ': 0.37; 'url:en': 0.39; 'some': 0.40; 'your': 0.60; 'more': 0.63; 'capable': 0.65; 'improvement.': 0.66; 'promise': 0.66; 'jul': 0.72; 'vital': 0.76; 'chrisa': 0.84; 'absolutely': 0.88; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=tG/lhri2kZG1R81VDgFv2Adg6hQ7/Jr/qWfDKTLMkOI=; b=Rcb4nDtRs42R4kGgmlOpXk5K2rd0otuMc6o4uMwvJTr0yyDdUe+oaVvPpj51XgQ3TD gvM5a/ds6wfgiENHsgczIhYLebcUdwuBmCFqJyEHYX7RToi05IskPrh91KD+toq6XqEc p5+Dea7G/JjDcYVVwX9iOwSjtLjO0Mp/zVZZoe2x3fvNlrb2sCqzkDkvc77tT4LX44KV Oi5BjsRwqL1q+eYg/TBDDQSxPk+7pqdfNUzP2iy831+H67hBOOibqa/GMVSS0Dh59Gw6 ekD2hIxPq08uetgBIPNfO6EoRzwZowEIepFFda0hFAGAN7b5Ex9FooAw05IODxVYT1kc ayXg== MIME-Version: 1.0 X-Received: by 10.50.29.75 with SMTP id i11mr20978802igh.50.1436900143374; Tue, 14 Jul 2015 11:55:43 -0700 (PDT) In-Reply-To: <87r3oad1rl.fsf@elektro.pacujo.net> References: <55A3A853.4040006@rece.vub.ac.be> <55A3C366.6060602@rece.vub.ac.be> <87fv4r1fre.fsf@jester.gateway.sonic.net> <877fq3nuwo.fsf@elektro.pacujo.net> <87pp3vm93f.fsf@elektro.pacujo.net> <55a54818$0$1652$c3e8da3$5496439d@news.astraweb.com> <87vbdmd48e.fsf@elektro.pacujo.net> <55a54fb2$0$1646$c3e8da3$5496439d@news.astraweb.com> <87r3oad1rl.fsf@elektro.pacujo.net> Date: Wed, 15 Jul 2015 04:55:43 +1000 Subject: Re: Possibly Pythonic Tail Call Optimization (TCO/TRE) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436900151 news.xs4all.nl 2827 [2001:888:2000:d::a6]:41771 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93831 On Wed, Jul 15, 2015 at 4:37 AM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Tail call behaviour is not undefined in Python. There is a strong >> convention (followed by all implementations I know of) to follow the >> reference implementation's (CPython) behaviour, which is not to >> optimize tail calls. But even if an implementation chooses to not >> follow that, it's not *undefined behaviour*. It's just >> implementation-dependent behaviour. > > But in Scheme, tail call elimination is mandatory and thus can be relied > on. Unless that promise is made, you can't write code that depends on I think I'm beginning to understand. Tail call elimination is necessary to cope with a system of programming that has deliberately excluded certain other options (eg mutables, in pure functional languages), but is not as important in a more fully-featured language. Constant folding would be the same way; it's not absolutely critical, and if Python doesn't support it for some particular expression then it's not going to kill you, but in SPL [1] it would be a vital efficiency improvement. Scheme needs TCE because of the way you have to write code for Scheme to be even capable of executing it; Python doesn't, because you can write your code to not need TCE. [1] https://en.wikipedia.org/wiki/Shakespeare_(programming_language)#Constants_and_Assignment_of_Values ChrisA