Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.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; 'anyway.': 0.04; 'debug': 0.04; 'received:134': 0.05; 'calls.': 0.07; 'indication': 0.09; 'loop.': 0.09; 'preferable': 0.09; 'runtime': 0.09; 'worse': 0.09; 'anyway': 0.11; 'stack': 0.13; 'detects': 0.16; 'received:ac.be': 0.16; 'reedy': 0.16; 'something.': 0.16; 'tracebacks': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'implementing': 0.18; 'version.': 0.18; '>>>': 0.20; '2015': 0.20; 'fraction': 0.22; 'precise': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'developers': 0.26; 'chris': 0.26; '14,': 0.27; 'function': 0.28; 'fine': 0.28; 'record': 0.29; 'does,': 0.29; 'tail': 0.29; 'program,': 0.29; 'print': 0.30; 'subject:/': 0.30; 'call.': 0.30; 'compared': 0.30; 'received:be': 0.30; 'writes': 0.30; 'guess': 0.31; 'probably': 0.31; 'core': 0.32; 'getting': 0.33; 'doubt': 0.33; 'traceback': 0.33; 'tue,': 0.34; 'nothing.': 0.35; 'but': 0.36; 'there': 0.36; 'cases': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'no,': 0.38; 'drop': 0.38; 'loss': 0.38; 'to:addr:python.org': 0.40; 'some': 0.40; 'high': 0.60; 'behavior': 0.61; 'per': 0.62; 'course': 0.62; 'lose': 0.63; 'between': 0.65; 'records': 0.70; 'jul': 0.72; 'calls,': 0.84; 'iterative': 0.84; 'loose': 0.84; 'pardon': 0.84; 'sometimes.': 0.84; 'dream': 0.95 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnMGAB8iplWGuA9G/2dsb2JhbABbhCsBJIMkwBUCggoBAQEBAQGFLwEBBCNVEQsYAgIFFgsCAgkDAgECAUUTBgICiCq5GZEthQQBAQgCIIEiiiqFDRaCUoFDAQSUOIwLiDaQPSZjgxptgksBAQE Date: Wed, 15 Jul 2015 11:10:03 +0200 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Possibly Pythonic Tail Call Optimization (TCO/TRE) References: <55A3A853.4040006@rece.vub.ac.be> <55A3C366.6060602@rece.vub.ac.be> <87fv4r1fre.fsf@jester.gateway.sonic.net> <87bnff1eks.fsf@jester.gateway.sonic.net> <87d1zunctp.fsf@elektro.pacujo.net> <87k2u2eu67.fsf@elektro.pacujo.net> <55A51662.4090007@rece.vub.ac.be> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436951405 news.xs4all.nl 2883 [2001:888:2000:d::a6]:36821 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 5918 X-Received-Body-CRC: 3815776708 Xref: csiph.com comp.lang.python:93855 On 07/15/2015 02:41 AM, Terry Reedy wrote: > On 7/14/2015 10:02 AM, Antoon Pardon wrote: >> On 07/14/2015 03:43 PM, Chris Angelico wrote: >>> On Tue, Jul 14, 2015 at 11:38 PM, Marko Rauhamaa >>> wrote: > >>>> No, tail call optimization doesn't change the behavior of the program, >>>> for the worse anyway. >>> It does, because you lose traceback records. That's pretty significant >>> when you come to try to debug something. >> >> I doubt it would be really significant. Not compared to writing it >> iteratively. >> When you write it iteratively, you don't get to keep a traceback >> record per time >> you go throught the loop. So the traceback records you loose in tale >> call elimination >> would be the traceback records you wouldn't have anyway in the >> iterative version. > > To repeat: loosing tracebacks is probably fine when the function has a > single *recursive* tail call. This are precise the cases when it is > simple and perhaps preferable to use a loop. But *recursive* tail > calls are only a small fraction of all tail calls. So most of the > time, the loss *would* be significant. Consider But it doesn't need to be all or nothing. How about the following possibility. When the runtime detects a serie of tail calls, it will keep the bottom three and the top three backtrace records of the serie. And when it needs to print a stacktrace it writes an indication that some tracebacks are missing. I think that would be a workable compromise between workable tail call recursion and usefull stacktraces. Now of course there are some other problems like what if the tail call is into a C-function. I don't think you want to drop a stack frame in those circumstances. So I guess implementing this and getting all corner cases right, will not be trivial and I understand if the core developers don't consider this a high priority. But one likes to dream sometimes. -- Antoon Pardon