Skip to content
This repository has been archived by the owner on Nov 12, 2017. It is now read-only.

Bogdanp/tcopy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tcopy

Do not use this.

A direct tail call optimizing decorator for Python.

Examples:

from tcopy import tco

@tco
def fib(n, x=0, y=1):
    if n == 0:
        return x
    return fib(n - 1, y, x + y)

The tco decorator will rewrite fib into the following at definition time:

def fib(n, x=0, y=1):
    while 1:
        if n == 0:
            return x
        n, x, y = n - 1, y, x + y

Quirks

tco uses inspect.getsource to grab a function's source code from disk. Because of this, the decorator does not work in the Python REPL.

About

Tail call optimization for Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages