Content deleted Content added
Fix vandalism; undid revision 344973526 by 202.57.49.232 (talk) |
Revert even further to get rid of more vandalism |
||
Line 1:
In [[computer science]], '''tail recursion''' (or '''tail-end recursion''') is a special case of [[Recursion_(computer_science)|recursion]] in which the last operation of the function, the [[tail call]], is a recursive call. Such recursions can be easily transformed to iterations. Replacing recursion with [[iteration]], manually or automatically, can drastically decrease the amount of [[Call stack|stack]] space used and improve efficiency. This technique
==Description==
Line 13:
#''If'' (if ''E<sub>0</sub>'' ''E<sub>1</sub>'' ''E<sub>2</sub>'') ''is in tail position, then both E<sub>1</sub> and E<sub>2</sub> are in tail position.''
==Examples==
Take this [[Scheme (programming language)|Scheme]] program as an example:
Line 33:
;; to calculate the product of all non-negative integers
;; less than or equal to n.
(define
(lambda (n)
(let fact ([i n] [acc 1]) (if (zero? i)
acc
(fact (- i 1) (* acc i))))))
</source>
|