Tail Recursion and Tail Call Optimization: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
Okay, I delayed this way more than I thought I would... |
|||
Line 1: | Line 1: | ||
== What is a tail call? == |
== What is a tail call? == |
||
Formally, a call within a function is a tail call if the caller does not modify the state after the call and before returning. |
|||
Informally, a tail call is when a function calls another function, and returns immediately. In assembly, it's when a CALL and a RET instructions are found right next to each other. For example, in the following code: |
Informally, a tail call is when a function calls another function, and returns immediately. In assembly, it's when a CALL and a RET instructions are found right next to each other. For example, in the following code: |
||
Line 46: | Line 44: | ||
As you can see, there is no operation between <code>CALL</code> and <code>RET</code> this time. |
As you can see, there is no operation between <code>CALL</code> and <code>RET</code> this time. |
||
== Optimizing a tail call == |
== Optimizing a tail call == |
||