Wikipedia has a good explanation of the call stack and why stack overflows happen. Basically, when a function calls another function, the chain of calls and their parameters need to be stored on the call stack and this uses stack space.

A language needs to be designed to handle deep recursion by allocating heap memory to store and manage the call stack and parameters itself and avoiding nested calls. One side-effect is that this is usually much slower than letting the system handle it, so unless recursion is important, it is better not to do it.

There is an interesting recursion limit page that lists the recursion limits for various languages, although it says that AutoHotkey has a limit of 827, so the page might not be up-to-date. If you are able to do deep recursion in AutoHotkey, it may be that AutoHotkey was unable do that at some point and was rewritten to do so.

It is difficult to tell what the recursion limits are for most languages without testing them out. Some have arbitrarily low recursion limits to mitigate unintentional recursion but these can be increased with a command/setting, however this itself may be limited depending on the settings used to compile the language, which may either enable stack use or own stack management, and may compile with a larger or smaller reserved stack size to allow deeper recursion.

Last edited by Khaled; 01/02/15 11:39 PM.