Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93927

Re: A new module for performing tail-call elimination

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!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; '16,': 0.03; 'elif': 0.04; 'indicating': 0.05; 'none:': 0.05; 'assignment': 0.07; 'true)': 0.07; 'ugly': 0.07; 'cc:addr:python-list': 0.09; '(none,': 0.09; 'false)': 0.09; 'subject:module': 0.09; 'stack': 0.13; 'def': 0.13; 'thu,': 0.15; 'algorithmic': 0.16; 'fn)': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'trivially': 0.16; 'wrote:': 0.16; 'example.': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'machine': 0.21; '%s"': 0.22; 'header:In-Reply-To:1': 0.24; 'message- id:@mail.gmail.com': 0.27; 'change,': 0.27; 'tail': 0.29; 'raise': 0.29; 'code': 0.30; "can't": 0.32; 'point': 0.33; 'though.': 0.33; 'received:google.com': 0.35; 'next': 0.35; 'could': 0.35; 'replace': 0.35; 'pm,': 0.36; 'subject:: ': 0.37; 'turned': 0.38; 'anything': 0.38; 'subject:-': 0.39; 'rather': 0.39; 'easy': 0.60; 'collection': 0.60; 'maximum': 0.61; 'course': 0.62; 'here': 0.66; 'jul': 0.72; 'chrisa': 0.84; 'improved.': 0.84; 'odd,': 0.84; 'pardon': 0.84; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=tDkinIulLQXxmIjeKqWaQRMtzU9UQfM7a2D887gq89U=; b=v2rIJQSgkm5t3DWVdCG9D0PvqromOg6CQRKZIJH5CUV5VZZdNVNzKSIvFHHhnc7DZA 9gcdmMhgEy/V43r/Sfpz63dCK6Dlwjj4Ja6HBRnnNQniUlzOhYS4UdxUjV3kdkAsarPK 7mR3Oxv2w0LRBv1470hdIBaFXVxyb1VaAUHECjaXHfKAA+rXbt9hI7aEwXWXPOOAdxF/ YyVXmlgbxqZBPCOxhwnnIi3NMdX/6jhf/rooPYJ9ovFsGxnyAFjHi5ShjGO7STIQJbz1 fhul2keBluTgCiAyeTsYzX/E0aYSjktUIRXUcVsuJETnGbkJsNZAxJ7wkLKXsnTDpuG2 6HZg==
MIME-Version 1.0
X-Received by 10.107.4.1 with SMTP id 1mr10825798ioe.10.1437054479916; Thu, 16 Jul 2015 06:47:59 -0700 (PDT)
In-Reply-To <55A7B309.8080903@rece.vub.ac.be>
References <55a3dcd9$0$3024$426a34cc@news.free.fr> <mailman.532.1436952589.3674.python-list@python.org> <55a76628$0$2846$c3e8da3$76491128@news.astraweb.com> <55A78A42.4090506@rece.vub.ac.be> <CAPTjJmr4TJuMpgPm_cuMo_eM-xuNfgyLbTFvqA36mFvpNxQ1UA@mail.gmail.com> <55A7B309.8080903@rece.vub.ac.be>
Date Thu, 16 Jul 2015 23:47:59 +1000
Subject Re: A new module for performing tail-call elimination
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.582.1437054482.3674.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1437054482 news.xs4all.nl 2930 [2001:888:2000:d::a6]:33150
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:93927

Show key headers only | View raw


On Thu, Jul 16, 2015 at 11:35 PM, Antoon Pardon
<antoon.pardon@rece.vub.ac.be> wrote:
> 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
>
> Any collection of functions that tail calls each other can rather
> trivially be turned into a state machine like the above. You can
> just paste in the code of the individual functions and replace
> the return call combo's with an assignment indicating which 'function'
> is to be 'called' next and its arguments.

That's not an algorithmic change, though. That's just a mechanical
change, and a poorly-written one. My point was that I have yet to see
anything that demands TCO and can't be algorithmically improved. The
best so far has been a quicksort that uses TCO to guarantee a maximum
on stack usage.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

A new module for performing tail-call elimination "Th. Baruchel" <baruchel@no.spam.gmx.dot.com> - 2015-07-13 15:44 +0000
  Re: A new module for performing tail-call elimination Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-15 11:29 +0200
    Re: A new module for performing tail-call elimination Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-07-16 18:07 +1000
      Re: A new module for performing tail-call elimination Robin Becker <robin@reportlab.com> - 2015-07-16 10:13 +0100
      Re: A new module for performing tail-call elimination Robin Becker <robin@reportlab.com> - 2015-07-16 10:28 +0100
        Re: A new module for performing tail-call elimination Marko Rauhamaa <marko@pacujo.net> - 2015-07-16 12:56 +0300
      Re: A new module for performing tail-call elimination Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-16 12:41 +0200
        Re: A new module for performing tail-call elimination Steven D'Aprano <steve@pearwood.info> - 2015-07-17 04:58 +1000
          Re: A new module for performing tail-call elimination Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-17 11:00 +0200
      Re: A new module for performing tail-call elimination Chris Angelico <rosuav@gmail.com> - 2015-07-16 21:11 +1000
      Re: A new module for performing tail-call elimination Jeremy Sanders <jeremy@jeremysanders.net> - 2015-07-16 13:29 +0200
      Re: A new module for performing tail-call elimination Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-16 15:35 +0200
      Re: A new module for performing tail-call elimination Chris Angelico <rosuav@gmail.com> - 2015-07-16 23:47 +1000
        Re: A new module for performing tail-call elimination Paul Rubin <no.email@nospam.invalid> - 2015-07-17 20:06 -0700
      Re: A new module for performing tail-call elimination Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-16 16:21 +0200
      Re: A new module for performing tail-call elimination Chris Angelico <rosuav@gmail.com> - 2015-07-17 00:27 +1000
      Re: A new module for performing tail-call elimination Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-16 17:14 +0200
      Re: A new module for performing tail-call elimination Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-16 10:17 -0600
      Re: A new module for performing tail-call elimination Ethan Furman <ethan@stoneleaf.us> - 2015-07-16 10:54 -0700
      Re: A new module for performing tail-call elimination Ethan Furman <ethan@stoneleaf.us> - 2015-07-16 11:02 -0700
      Re: A new module for performing tail-call elimination Terry Reedy <tjreedy@udel.edu> - 2015-07-16 15:45 -0400
      Re: A new module for performing tail-call elimination Ethan Furman <ethan@stoneleaf.us> - 2015-07-16 12:58 -0700
      Re: A new module for performing tail-call elimination Robin Becker <robin@reportlab.com> - 2015-07-17 09:57 +0100
    Re: A new module for performing tail-call elimination Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-07-16 13:23 +0200
  Re: A new module for performing tail-call elimination Terry Reedy <tjreedy@udel.edu> - 2015-07-15 17:19 -0400
  Re: A new module for performing tail-call elimination Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-16 09:45 +0200
  Re: A new module for performing tail-call elimination Terry Reedy <tjreedy@udel.edu> - 2015-07-16 15:34 -0400
    Re: A new module for performing tail-call elimination Marko Rauhamaa <marko@pacujo.net> - 2015-07-16 22:45 +0300
      Re: A new module for performing tail-call elimination Terry Reedy <tjreedy@udel.edu> - 2015-07-17 15:47 -0400
        Re: A new module for performing tail-call elimination Marko Rauhamaa <marko@pacujo.net> - 2015-07-17 23:55 +0300
          Re: A new module for performing tail-call elimination Terry Reedy <tjreedy@udel.edu> - 2015-07-17 20:40 -0400
            Re: A new module for performing tail-call elimination Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-07-19 10:39 +1200
          Re: A new module for performing tail-call elimination Chris Angelico <rosuav@gmail.com> - 2015-07-18 10:47 +1000
          Re: A new module for performing tail-call elimination Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-07-19 10:39 +1200
      Re: A new module for performing tail-call elimination Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-07-19 10:39 +1200
        Re: A new module for performing tail-call elimination Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-19 01:09 +0100
        Re: A new module for performing tail-call elimination MRAB <python@mrabarnett.plus.com> - 2015-07-19 01:19 +0100
        Re: A new module for performing tail-call elimination Marko Rauhamaa <marko@pacujo.net> - 2015-07-19 09:29 +0300
  Re: A new module for performing tail-call elimination Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-17 10:06 +0200

csiph-web