Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Tail call optimizer

Name: Anonymous 2007-09-28 2:20 ID:9iEWgcnk

Hey /prog/
Check out my tail call decorator for Python.

def tailcall(f):
    '''Decorator that implements tail call optimization.
    Supports cooperative tail call - even when only one of the functions
    is decorated, and all exceptions pass through it. You can tell the
    functions that have been tail optimized because they have "tco" before
    them in the stack frame.
    The only caveat is that if you attempt to decorate a function that
    isn't called in a tail recursive fashion from another decorated
    function, you'll get wrong results.'''
   
    tdata = [False] #[Optimizing?]
    DO_CALL = object() #Call marker
    def tco(*a, **aa):
        if tdata[0]:
            return DO_CALL, a, aa
        else:
            tdata[0] = True
            ret = f(*a, **aa)
            while type(ret) is tuple and ret and ret[0] is DO_CALL:
                ret = f(*ret[1], **ret[2])
            tdata[0] = False
            return ret
    tco.__doc__ = f.__doc__
    return tco

Name: Anonymous 2007-09-28 3:18 ID:saiNGU0D

ONE WORD, FORCED INDENTATION OF THE CODE, THREAD OVER

Name: Anonymous 2007-09-28 3:56 ID:Heaven

@tailcall is a meme now?

Name: Anonymous 2007-09-28 4:18 ID:50SeRwlm

>>1
Lol, my code is already being distributed, it's a success!

Name: Anonymous 2007-09-28 14:19 ID:yGWjkrrI

>>4
You should post this on programming.reddit.

Name: Anonymous 2011-12-09 8:35

O® EN

Name: Anonymous 2012-06-25 23:44

ᚇ蔩蕣馘獕ᙃ虄ኃ☇喐悁԰̉㑰ᢈ邇圥㈲鄈䄂┡杖碙䞗腣ᔣ祀鑂鎕ᙉ䚕匤蠧ᑑ蜨⎀    摨ĵ慖噡㝁蘠䡹֖ᥰ蜓脤灗䝩睄፤朓襖契鍣饧™礉鐅慓ᅆ酄р聢冕吵ᥥچ艨悃⤂ ≧皑葱㜨舗猩吐餢Ĉ饦銘䚓怳☩餒祕刃Ճᙃ栦鍣㐓㠇㝃ԣ阣ࡓƗ㝓镲㘑थ衈錁玗镓䀴ᜑ፠ݴ冕܈㤅䌔⡂表䢂怠鄠瞔䍠鍐㈩ѓ䅑⎗㦖㕓葠द≆♓⎂慃ቓؙ䅢ܰᤨ艘㢑ɩᜠ␙敳բᅵᄤ蔁坒扰熒桇楂ॢ㊓⍔慖瀘遗䕡㈈茢蘵鈀‴癸⊑捧ᚕ⅁錃礕搳塡褖灇ʄ䡂嚇睰㆑褣䈶恳䜦ᄠ䉒隂ፕ䥰焈☑∰钆㝶畁塇㦉镢爕ᘕ袐舥☓䤲光ݑ呸醀ᤙ遅們遒ᡸ․⡙ᝨ㙹≁衉焁ᑈऩ杈̀㍩䐖䡢ᅘ塘唴☃̥塤䅆攦ݢ⌃⑳楒搹Ѡ阆吓砑㞐ᒃ䍱蘱靦瑩⡁鐸䕦脇冂᝘琠牀ᐶ㖃ٙ獱獱坐桹蚕⍓ၲ炖䐅▃蝔萤摡蝣ᜠࡳ遧၇ॸ衸恵爀剑嘹❖頄࢕䞑ᔢ⍷術≘灀眆

Don't change these.
Name: Email:
Entire Thread Thread List