Does MATLAB perform tail call optimization?

Posted by Shea Levy on Stack Overflow See other posts from Stack Overflow or by Shea Levy
Published on 2011-03-16T14:31:21Z Indexed on 2011/03/16 16:10 UTC
Read the original article Hit count: 277

I've recently learned Haskell, and am trying to carry the pure functional style over to my other code when possible. An important aspect of this is treating all variables as immutable, i.e. constants. In order to do so, many computations that would be implemented using loops in an imperative style have to be performed using recursion, which typically incurs a memory penalty due to the allocation a new stack frame for each function call. In the special case of a tail call (where the return value of a called function is immediately returned to the callee's caller), however, this penalty can be bypassed by a process called tail call optimization (in one method, this can be done by essentially replacing a call with a jmp after setting up the stack properly). Does MATLAB perform TCO by default, or is there a way to tell it to?

© Stack Overflow or respective owner

Related posts about matlab

Related posts about functional-programming