Well, mostly there seems to be resistance to turning Python into Scheme, because, well, if you like Scheme it's already there for you to use (I'd make a joke here about how a future revision of Scheme should turn non-tail-recursive functions into a compiler error, but I'm afraid somebody would actually think that's a good idea). Oh, and for the record: I'm against tail elimination in Python simply because it seems inevitably to lead to people writing obfuscated, hard-to-read code simply for the sake of having a tail-recursive function, and Python is, well, not about that: it's about clear, readable code.
But as others have pointed out, one of the biggest problems, to me as a Python programmer, is the zeal with which FP folks approach this; it's not a case of "we want the ability to do more FP stuff in Python", it's "FP should be the one and only way in which programmers are allowed to write code". You yourself are leaning that way with your straw-man "hostility to abstraction" swipe (hint: OOP is also abstraction. It's different abstraction than FP, but it's abstraction nonetheless).
Meanwhile I'm quite happy to take advantage of closures, comprehensions, coroutines, function composition and all the other things Python lets me do, without thinking that has to be the only way I think about or write code. So maybe the problem is in yourself and not in Python :)
I'm against tail elimination in Python simply because it seems inevitably to lead to people writing obfuscated, hard-to-read code simply for the sake of having a tail-recursive function, and Python is, well, not about that: it's about clear, readable code.
That's a pretty weak reason. You can (ab)use many of Python's features to make extremely obfuscated code - such as decorators, metaclasses, context managers etc. etc.
The best reason (although I don't think it is a good one) against tail-call-elimination is confusing stack traces in case of exceptions.
Tail call elimination also actually allows you to write clearer code while still being efficient.
Exactly. And stack traces can be fixed as well by just keeping the first and the last call in the stack (or just the last), along with the number of omitted calls. It'd require an additional property in stack frames: the number of tail call to the same function it is. This would still mess with cooperative recursion, but that's a lesser issue.
Besides, it wouldn't be to hard to supply a debug parameter that turns off tail call elimination. If you are debugging an exception where the stack indicates eliminated frames - you would just turn it on and see the full exception.
Of course, then your stack might blow long before you get your exception though :)
4
u/ubernostrum yes, you can have a pony Nov 11 '08
Well, mostly there seems to be resistance to turning Python into Scheme, because, well, if you like Scheme it's already there for you to use (I'd make a joke here about how a future revision of Scheme should turn non-tail-recursive functions into a compiler error, but I'm afraid somebody would actually think that's a good idea). Oh, and for the record: I'm against tail elimination in Python simply because it seems inevitably to lead to people writing obfuscated, hard-to-read code simply for the sake of having a tail-recursive function, and Python is, well, not about that: it's about clear, readable code.
But as others have pointed out, one of the biggest problems, to me as a Python programmer, is the zeal with which FP folks approach this; it's not a case of "we want the ability to do more FP stuff in Python", it's "FP should be the one and only way in which programmers are allowed to write code". You yourself are leaning that way with your straw-man "hostility to abstraction" swipe (hint: OOP is also abstraction. It's different abstraction than FP, but it's abstraction nonetheless).
Meanwhile I'm quite happy to take advantage of closures, comprehensions, coroutines, function composition and all the other things Python lets me do, without thinking that has to be the only way I think about or write code. So maybe the problem is in yourself and not in Python :)