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.000 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; 'syntax': 0.13; 'def': 0.13; 'async': 0.16; 'constructs': 0.16; 'fn)': 0.16; 'looping': 0.16; 'loops': 0.16; 'reedy': 0.16; 'sense,': 0.16; 'syntactical': 0.16; 'wrote:': 0.16; 'example.': 0.18; 'language': 0.19; '>>>': 0.20; 'all,': 0.20; '%s"': 0.22; 'mind.': 0.22; 'am,': 0.23; 'needed.': 0.23; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'opposed': 0.27; '~ethan~': 0.29; 'raise': 0.29; 'certain': 0.31; 'another': 0.32; 'core': 0.32; 'add': 0.34; 'could': 0.35; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'really': 0.37; 'enough': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'easy': 0.60; 'charset:windows-1252': 0.62; 'here': 0.66; 'await': 0.76; '2:02': 0.84; 'odd,': 0.84; 'pardon': 0.84; 'received:10.1.10': 0.84; 'wow': 0.84; 'ethan': 0.91; 'furman': 0.91 Date: Thu, 16 Jul 2015 12:58:44 -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> <55A7F1A7.9000203@stoneleaf.us> In-Reply-To: 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437076730 news.xs4all.nl 2859 [2001:888:2000:d::a6]:38789 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93959 On 07/16/2015 12:45 PM, Terry Reedy wrote: > On 7/16/2015 2:02 PM, Ethan Furman wrote: >> On 07/16/2015 06:35 AM, Antoon Pardon wrote: > >>> 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). > > What you call ugly is an example of the core of the proof that alternation and indefinite > while looping are enough for turing completeness, and that no recursive syntax is needed. > Another way to put it is that while loops perform recursion in the operational sense, as > opposed to the syntactical sense. And we add new constructs and new language features to make certain ways of thinking/programming easier -- async and await come to mind. ;) After all, we don't really even need while loops as we could get by with if and goto. -- ~Ethan~