Tail recursion: Difference between revisions

Content deleted Content added
Line 14:
 
==Examples==
 
Take this [[Scheme (programming language)|Scheme]] program as an example:
 
<source lang="scheme">
;; factorial : number -> number
;; to calculate the product of all non-negative integers
;; less than or equal to n.
(define (factorial n)
(if (= n 0)
1
(* n (factorial (- n 1)))))
</source>
 
This program is not written in a tail recursion style. Now take this [[Scheme (programming language)|Scheme]] program as an example:
 
<source lang="scheme">