Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'cpython': 0.05; 'implements': 0.07; 'seemed': 0.07; 'loop.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'example:': 0.10; 'jan': 0.11; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'rewritten': 0.16; 'wrote:': 0.16; 'typical': 0.18; 'posted': 0.21; 'fairly': 0.22; '(usually': 0.22; 'function:': 0.22; 'code.': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'equivalent': 0.27; 'switch': 0.27; 'function': 0.28; 'symbols': 0.29; 'tail': 0.29; 'call.': 0.30; 'putting': 0.30; 'operations': 0.31; 'compiled': 0.32; 'jump': 0.33; 'symbol': 0.33; 'but': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'skip:n 10': 0.62; 'compiles': 0.84; '(always': 0.91; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: A new module for performing tail-call elimination Date: Fri, 17 Jul 2015 15:47:19 -0400 References: <55a3dcd9$0$3024$426a34cc@news.free.fr> <55A6280C.3090602@rece.vub.ac.be> <55A76116.7070708@rece.vub.ac.be> <87lhefanui.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-98-114-97-173.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 In-Reply-To: <87lhefanui.fsf@elektro.pacujo.net> 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437162474 news.xs4all.nl 2959 [2001:888:2000:d::a6]:54254 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:94027 On 7/16/2015 3:45 PM, Marko Rauhamaa wrote: > > Nobody seemed to notice that I just posted a fairly typical tail call > function: Because non-recursive tail calls are completely normal. Example: return len(self.children) Even tail operations like return a + b are tail calls if rewritten as return a.__add__(b) (usually but not always equivalent) or rewritten as return operator.add(a, b) (always equivalent) or compiled by an implementation as an equivalent internal function call. It happens to be that CPython implements calls to symbol operator functions by putting the bodies of such functions into a C switch inside a while loop. It this compiles operator symbols into bytecodes that cause a jump to the corresponding code. -- Terry Jan Reedy