Possibly Pythonic Tail Call Optimization (TCO/TRE)

Ned Batchelder ned at nedbatchelder.com
Wed Jul 15 12:45:55 CEST 2015

On Wednesday, July 15, 2015 at 2:44:55 AM UTC-4, Marko Rauhamaa wrote:
> Gregory Ewing <greg.ewing at canterbury.ac.nz>:
> > Marko Rauhamaa wrote:
> >> It might even be tail-call optimized by Python. Only you can't count
> >> on it because the language spec doesn't guarantee it.
> >
> > The language spec might permit it, but the BDFL has explicitly
> > expressed a dislike for the idea of implicit tail call removal, so
> > it's unlikely to ever happen in CPython.
> Permitting wouldn't be enough.
> The other problem for tail call elimination is the requirement that
> functions return None by default. Smooth tail call elimination would
> require that Python leave the default return value unspecified.

I don't understand this, can you explain more? Are you saying that the
Python specification shouldn't specify what x becomes?:

    def who_knows():

    x = who_knows()


More information about the Python-list mailing list