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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; '(even': 0.05; 'none:': 0.05; 'true)': 0.07; 'ugly': 0.07; '(none,': 0.09; 'false)': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'subject:module': 0.09; 'def': 0.13; 'fn)': 0.16; 'trivially': 0.16; 'wrote:': 0.16; 'example.': 0.18; '%s"': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'chris': 0.26; '~ethan~': 0.29; 'raise': 0.29; 'ones,': 0.33; 'could': 0.35; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'subject:-': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'easy': 0.60; 'charset:windows-1252': 0.62; 'course': 0.62; 'real-world': 0.66; 'here': 0.66; 'odd,': 0.84; 'pardon': 0.84; 'received:10.1.10': 0.84; 'wow': 0.84 Date: Thu, 16 Jul 2015 11:02:15 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: A new module for performing tail-call elimination References: <55a3dcd9$0$3024$426a34cc@news.free.fr> <55a76628$0$2846$c3e8da3$76491128@news.astraweb.com> <55A78A42.4090506@rece.vub.ac.be> <55A7B309.8080903@rece.vub.ac.be> In-Reply-To: <55A7B309.8080903@rece.vub.ac.be> Content-Type: text/plain; charset=windows-1252; format=flowed 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437069749 news.xs4all.nl 2897 [2001:888:2000:d::a6]:41584 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93945 On 07/16/2015 06:35 AM, Antoon Pardon wrote: > On 07/16/2015 01:11 PM, Chris Angelico wrote: >> Unless, of course, *all* TCO examples, even real-world ones, could be >> trivially reimplemented some other way, a theory which is gaining >> currency... > > Of course they could be rather trivially reimplemented. They would > also become rather ugly and less easy to comprehend. > > Here is one way to do the odd, even example. > > def even(n): > return odd_even('even', n) > > def odd(n): > return odd_even('odd', n) > > def odd_even(fn, n): > while fn is not None: > if fn == 'even': > fn, n = (None, True) if n == 0 else ('odd', n - 1) > elif fn == 'odd': > fn, n = (None, False) if n == 0 else ('even', n - 1) > else: > raise ValueError("Unknown state: %s" % fn) > return n Wow -- definitely uglier and less easy to understand than the original (even if the original had had the error-checking). -- ~Ethan~