Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'removes': 0.05; 'undefined': 0.07; 'cc:addr:python-list': 0.09; 'caller.': 0.09; 'implies': 0.09; 'spec': 0.09; 'python': 0.10; 'python.': 0.11; 'stack': 0.13; 'wed,': 0.15; 'explicitly': 0.15; 'evaluates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'none),': 0.16; 'similarly,': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'passes': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; '(or': 0.23; 'header:In- Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'behaviour': 0.29; 'tail': 0.29; 'subject:/': 0.30; '15,': 0.30; 'entry': 0.31; 'statement': 0.32; 'url:python': 0.33; 'received:google.com': 0.35; 'url:org': 0.36; 'evaluation': 0.36; 'subject:: ': 0.37; 'where': 0.40; 'still': 0.40; 'url:3': 0.60; 'behavior': 0.61; 'back': 0.62; 'therefore': 0.67; 'stated': 0.70; 'jul': 0.72; 'present.': 0.72; 'chrisa': 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=Y3ZoN7KNqIuv1p/YXDsFmDXoexKJTo5wsxRCZAm6SxI=; b=KrV6+hg/FFX+R9rSPUYwRzA5SuGSG37d79psCSKPPtH8pGsPQEGq+m2EFjaBccPuXT g/FkeFHUp0Pn5WbwWLYO+H5qRuGXAtS+7V/ttl46oxczMwUgrx6NfvrdD74jmNrLsfGi KlIUgnrBH78rrnuALNN7jK1OcDbO0DLTAjScgr/7BThyIgGxrGHJgLzqnUF7k9S8+UBo JH5MLccQWhovUBsWy1dYGhgzTjuQ1pY1+haib9OTN7bC/A1lvtXjNyPfBUzojHeuR87k Y4/SVwdYeV5kj1vPTGICFDZHv6SNjRyDmDcBWRV7+WW8fFpG5AiECOe023pnU0FKmKiW j+eQ== MIME-Version: 1.0 X-Received: by 10.107.159.66 with SMTP id i63mr57219564ioe.68.1436896378861; Tue, 14 Jul 2015 10:52:58 -0700 (PDT) In-Reply-To: <87vbdmd48e.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> Date: Wed, 15 Jul 2015 03:52:58 +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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436896381 news.xs4all.nl 2912 [2001:888:2000:d::a6]:47489 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93826 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 This implies that during the evaluation of its expression, the current function's call stack entry is still present. Tail call behaviour is therefore well defined: it is identical to any other expression evaluation, and then the final result is passed back to the caller. ChrisA