3 ms·
Hi, thanks -- this looks great! Does it support tail recursion (in constant space)?
by julian37 16y ago
Hi, thanks -- this looks great!
Does it support tail recursion (in constant space)?
- metageek 16y agoNo, because it compiles to Python. I suppose I could finagle some way to manage it for self-calls, by putting the whole function in a loop. Although that would bind the function name earlier than usual for Python. In Python, you can (in theory) do this: def fact(n,sofar): if n<2: return sofar else: return fact(n-1,n*sofar) f=fact fact=lambda n,sofar: 3 ...whereupon f(7,1)==3. I suppose I wouldn't really mind if Adder broke that consistently, but I don't think I like the idea of breaking it only for functions that do self-tail-calls.
- ckcheng 16y agoHow about considering Clojure's style of using recur to support self-tail-call optimization using explicit syntax?
- metageek 16y agoHmm. Maybe. I'd have to look closer. My main resistance is that I've used languages where you have to use special syntax for a recursive function, and I hate it. But this isn't quite the same thing.
- silentbicycle 16y agoDoes it really make sense to add a workaround-to-a-workaround?
- julian37 16y agoHave you considered using a "trampoline" function like this? http://paulbutler.org/archives/tail-recursion-in-python/ http://paulbutler.org/archives/tail-recursion-in-python/
- metageek 16y agoInteresting...no, I hadn't seen that before. I'll think about it.
- silentbicycle 16y agoYou'll get a lot out of _Lisp in Small Pieces_ (http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/LiSP.html http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/LiS...), as well. Python wouldn't be my first choice, and I'm unconvinced that Lisp-Py makes sense, but I'm sure you'll find ways to adapt it regardless.
- runningdogx 16y agoA flag to enable targeting stackless python instead of normal python?