2 ms·
You and I have a different definition of "semantics" when it comes to programming languages. Your code still achieves the same result, just in a different way.
by scott_s 17y ago
You and I have a different definition of "semantics" when it comes to programming languages. Your code still achieves the same result, just in a different way. That requirement - equivalent outcome - is how compilers decide what optimizations it can and can't perform. This is often stated as "optimizations can't change program semantics."
- bad_user 17y agoIf an optimization means that an algorithm reaches the desired result or not, that's not an optimization anymore. def fact(n, r=1): if n == 1: return r return fact(n-1, r * n) Regardless of any available stack-space you may have, for the above method (which can be tail-call optimized) try calculating fact(1000000). If that's the requirement, then without TCO this implementation is incorrect.
- eru 17y agoIndeed. Though you have to exclude preservation of timing (and memory usage) effects from your definition of semantics to make any optimization possible.