3 ms·
I agree that coding in the style of the language is important, and I can assure you that my python code has gotten a fair bit more pythonic since writing this :
by paulgb 18y ago
I agree that coding in the style of the language is important, and I can assure you that my python code has gotten a fair bit more pythonic since writing this :).
Still, there are times when things like this could be useful. Even though I code in python more than anything these days, I still find it useful to "think in scheme" sometimes, and having access to unlimited tail recursion helps. A fair bit of my code is experimental or write-once run-once, so as long as I can understand it performance and readability is not a huge issue.
> A little tip: tail_rec is a decorator [...]
Unfortunately, it's not that easy. The tail-recursive function itself needs to be able to reference itself (unmodified by a decorator) when it creates the lambda. There is a way around this (by having the function take a copy of itself as an argument, as in the y-combinator), but that has a negative net effect on readability.