Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'removes': 0.05; 'undefined': 0.07; 'cc:addr:python-list': 0.09; 'spec': 0.09; 'python': 0.10; 'python.': 0.11; 'stack': 0.13; 'wed,': 0.15; 'explicitly': 0.15; 'entries,': 0.16; 'evaluates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'none),': 0.16; 'occurs.': 0.16; 'reedy': 0.16; 'similarly,': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'passes': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; '(or': 0.23; 'unlike': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'chris': 0.26; 'skip:" 20': 0.26; 'message- id:@mail.gmail.com': 0.27; 'behaviour': 0.29; 'tail': 0.29; 'subject:/': 0.30; '15,': 0.30; "can't": 0.32; 'statement': 0.32; 'url:python': 0.33; 'definition': 0.34; 'received:google.com': 0.35; 'clear': 0.35; "isn't": 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'things': 0.38; 'anything': 0.38; 'where': 0.40; 'some': 0.40; 'url:3': 0.60; 'behavior': 0.61; 'back': 0.62; 'different': 0.63; 'course.': 0.67; 'stated': 0.70; 'jul': 0.72; 'chrisa': 0.84; 'concept.': 0.84; 'to:none': 0.91; 'url:reference': 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=5HlTB710smfGj9joZh3VCpNfh3fU79eTrwPJxlLnco8=; b=EDgSzKlV0fNetHRb7c9qTLBbw3Wt6KD5IvfJqRQzemqlzy0IltPdCMZrzW4mjtnr5R yNw8a55dXRDJ0/wjelYzfCpBUKbZLwNoetc/QcXjuByz4Woy7RybfqgNI1GY9BfPgsdE uEjHunagsWPbP9ctI7vONMt6T0x7+XOmvpiIRy5USc1bV0qfNKE7lbkE2OglXcB4lZA7 mYB43jCKWtRpRXAwXX+RnVNPbwZs5C6ZCPQrp/WFdP+Z0xZsdijaP+SxOC04ljLgPunz getzm2byim0GTbRFPqPZQOyfQX9LdhwjttluK9X5fFVawb+ORxhxC5AV7uz+8eyPw00E u3mw== MIME-Version: 1.0 X-Received: by 10.107.165.142 with SMTP id o136mr2356948ioe.120.1436929551095; Tue, 14 Jul 2015 20:05:51 -0700 (PDT) In-Reply-To: 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> Date: Wed, 15 Jul 2015 13:05:50 +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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436929554 news.xs4all.nl 2821 [2001:888:2000:d::a6]:39158 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93844 On Wed, Jul 15, 2015 at 11:01 AM, Terry Reedy wrote: > On 7/14/2015 1:52 PM, Chris Angelico wrote: >> >> On Wed, Jul 15, 2015 at 3:43 AM, Marko Rauhamaa wrote: >>> >>> I don't like the way integer overflows are explicitly undefined in >>> modern C. >>> >>> Similarly, I don't like the way tail call behavior is undefined in >>> Python. >> >> >> Where in the Python spec is it stated that tail call behaviour is >> undefined? The behaviour of the 'return' statement is well defined: it >> evaluates its expression (or None), *then* removes the top of the call >> stack and passes control back to the caller: >> >> https://docs.python.org/3/reference/simple_stmts.html#the-return-statement > > > I do not see anything there explicitly about call stacks. There isn't anything explicitly about call stacks, but it clearly states that the expression is evaluated, and *then* processing of the return statement occurs. Unlike C, Python doesn't have "undefined behaviour"; there are some things which are "implementation-defined", but that's a different concept. But the spec is reasonably clear by implication, in my opinion; if tail calls are allowed to remove stack entries, that definition will need to be edited. (That's not to say it can't be, of course. But it would be a change.) ChrisA