The hackyness/speed issues aside: When compiling/transpiling/whatever between languages, I have found that relying on regular procedure calls and TCO is generally a lot simpler than having to force the looping facility of one language into the semantics of another language. The only one I can actually imagine porting other loops to is the common lisp loop macro, but that is probably the most flexible looping facility…
Tail recursion in Python
21–30 of 87 posts
Re: Tail recursion in Python
#22Re: Tail recursion in Python
#23Someone recently pointed out to me you can bypass the recursion limit with an inbuilt decorator, because it's basically a memoiser. lru_cache, from the functools library. The example given in the docs [0] is: import functools @functools.lru_cache(maxsize=None) def fib(n): if n [0] https://docs.python.org/3/library/functools.html#functools.l...
Re: Tail recursion in Python
#24I'm not sure if there is any advantage when language/compiler does not provide a proper tail recursive optimization.
Re: Tail recursion in Python
#25A patch that implements TCO in Python with explicit syntax like 'return from f(x)' could likely get accepted, ending these hacks
Re: Tail recursion in Python
#26The hackyness/speed issues aside: When compiling/transpiling/whatever between languages, I have found that relying on regular procedure calls and TCO is generally a lot simpler than having to force the looping facility of one language into the semantics of another language. The only one I can actually imagine porting other loops to is the common lisp loop macro, but that is probably the most flexible looping facility…
With regards to stacks that can use all of the memory: Gambit and AFAIK Chicken behave that way, too. This is one of the reasons I chose Scheme over OCaml (and Haskell) over a decade ago when looking for a new language to move to.
Re: Tail recursion in Python
#27A patch that implements TCO in Python with explicit syntax like 'return from f(x)' could likely get accepted, ending these hacks
> So let me defend my position (which is that I don't want TRE in the language). If you want a short answer, it's simply unpythonic.
[0] http://neopythonic.blogspot.com.au/2009/04/tail-recursion-el...
Re: Tail recursion in Python
#28The hackyness/speed issues aside: When compiling/transpiling/whatever between languages, I have found that relying on regular procedure calls and TCO is generally a lot simpler than having to force the looping facility of one language into the semantics of another language. The only one I can actually imagine porting other loops to is the common lisp loop macro, but that is probably the most flexible looping facility…
With regards to stacks that can use all of the memory: Gambit and AFAIK Chicken behave that way, too. This is one of the reasons I chose Scheme over OCaml (and Haskell) over a decade ago when looking for a new language to move to.
Re: Tail recursion in Python
#29Code snippets you won't see if you have JS disabled: https://gist.github.com/ChrisPenner/c0b3f4feb054daa2f6370d2e... https://gist.github.com/ChrisPenner/c958afbf6e7a763c188d8b83...
JS fully disabled in this day and age?
I mean, I personally don't care; I've always been a little weird. But it is funny to see technical preferences as a signaling mechanism.
Funny, that is, until it hits a certain point... http://www.wired.co.uk/article/chinese-government-social-cre...
Re: Tail recursion in Python
#30Code snippets you won't see if you have JS disabled: https://gist.github.com/ChrisPenner/c0b3f4feb054daa2f6370d2e... https://gist.github.com/ChrisPenner/c958afbf6e7a763c188d8b83...
JS fully disabled in this day and age?
Also avoiding downloading JS libraries bigger than Quake while on the go.