3 ms·
This is good, but I'm surprised at the assertion that "We can see that the function is pure, and evaluate the function up-front to find ackermann(2, 2) must be
by tom_mellior 7y ago
This is good, but I'm surprised at the assertion that "We can see that the function is pure, and evaluate the function up-front to find ackermann(2, 2) must be equal to 7". I don't know of real-world compilers that would do this[1], since even pure functions can take arbitrary amounts of time to evaluate at compile time. The Ackermann function in particular is famous for its complexity -- it was constructed for complexity.
In the particular case of ackermann(2, 2) you should be able to do it with a moderate number of inlinings, but I don't think compilers often bother to inline more than one level of a recursive function.
[1] Of course you can force compile-time evaluation of code in some languages, like with Lisp macros or C++ templates. But that's not what's happening here.