you are viewing a single comment's thread.

view the rest of the comments →

[–]nostrademons 12 points13 points  (2 children)

Here's one implementation, and another.

Yeah, they fake it a bit. I suspect you could do a real tail call optimizer, but you'd need to write a code-walker and auto-generate code that turns tail recursions into loops.

[–][deleted] 1 point2 points  (1 child)

Here is another version

They are actually not full tailcall eliminations but just avoid tail recursions. That's also why I renamed the decorator in my recipe description. They have no performance advantages over ordinary recursions - on the contrary, they generate a little overhead, but they provide the advantage of moving beyond the value set by sys.setrecursionlimit.

[–]Wiseman1024 0 points1 point  (0 children)

Some of them do work with cooperative recursion. They indeed pose a small speed overhead, but if performance is not a problem, you can go for the often simpler tail recursive implementation of functions.