checkRecur: Check if a function is recursive
checkRecur will check code to ensure that it is recursive.
I = checkRecur(F) will function path F to check if F is recursive. F must be an absolute path
Contents
Remarks
Recursion comes in two flavors: Direct and Mutual
Direct recursion means that a function just calls itself; function A calls function A. This is the simplest form of recursion.
Mutual recursion means that a function calls another function, which then eventually calls the original function. Function A calls function B, which turns around and calls function A. This is still recursion, and where the stack comes into play.
checkRecur uses static analysis, served up via getcallinfo. While this does mean it can be quite performant, it also means that it can be tricked. For example, consider the following code:
function out = notRecur(in) if false out = notRecur(in); end end
Though statically, it appears that notRecur calls itself, in reality that code is never run, because false is never true. However, checkRecur will still return true.