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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:134': 0.05; 'rewrite': 0.07; 'subject:module': 0.09; 'url:github': 0.09; 'url:blog': 0.10; 'python': 0.10; 'syntax': 0.13; 'def': 0.13; 'module?': 0.16; 'received:ac.be': 0.16; 'wrote:': 0.16; '(see': 0.20; 'suppose': 0.22; 'consistent': 0.23; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'function': 0.28; 'that.': 0.30; 'received:be': 0.30; 'at:': 0.31; 'done': 0.35; 'false': 0.35; 'instance': 0.35; 'but': 0.36; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; '(with': 0.38; 'difference': 0.38; 'hi,': 0.38; 'format': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'suitable': 0.61; 'here': 0.66; 'decided': 0.66; 'finally': 0.70; 'pardon': 0.84 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnQGAPQmplWGuA9G/2dsb2JhbABbg2dEAYNIuhqFewKCCgEBAQEBAYUvAQEEI1URCxgCAgUWCwICCQMCAQIBRRMIAogquSKRLIUEAQEBBwEBAQEegSKKKoUNFoJSgUMBBJQ4hGyHH4FARYYxiSGDO4NhJoN9gzgBAQE Date: Wed, 15 Jul 2015 11:29:48 +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: A new module for performing tail-call elimination References: <55a3dcd9$0$3024$426a34cc@news.free.fr> In-Reply-To: <55a3dcd9$0$3024$426a34cc@news.free.fr> 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436952589 news.xs4all.nl 2857 [2001:888:2000:d::a6]:42941 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93857 On 07/13/2015 05:44 PM, Th. Baruchel wrote: > Hi, after having spent much time thinking about tail-call elimination > in Python (see for instance http://baruchel.github.io/blog/ ), I finally > decided to write a module for that. You may find it at: > > https://github.com/baruchel/tco > > Tail-call elimination is done for tail-recursion as well as for > continuation-passing style (cps) in a consistent syntax for both usages. > > Any tail-recursive function having the suitable format for being > embeddable in the Y combinator can be used here with no change at all > (with the main difference that tail-calls will be eliminated), but other > continuations can also be added Can you explain how you would do mutual recursive functions? Suppose I start with the following: def even(n): True if n == 0 else odd(n - 1) def odd(n): False if n == 0 else even(n - 1) How do I rewrite those with your module? -- Antoon Pardon