Compile a Recursive Function

The Wolfram Compiler support for functions nested inside other functions can be used to implement recursion.

The following is a simple implementation of a Factorial function. It takes a single integer and contains a nested inner function that calls itself. Notice how the only type annotation is the input argument. All other types are determined by the Wolfram Compiler.

Within its somewhat limited range of application, this function is speed competitive with the built-in Factorial function.

Related Examples

ja