;; Tail recursion demonstration ;; The idea is to develop two recursive procedures ;; that do the same work, except that one ;; uses tail recursion and the other doesn't ;; We force the recursion to an excessive depth and ;; watch the non tail recursive procedure die ;; due to insufficient stack space, while the other ;; one can complete. ;; no tail recursion (define (func1 x) (if (= x 0) 0 (+ x (func1 (- x 1))))) ;; tail recursion (define (func2 x sum) (if (= x 0) sum (func2 (- x 1) (+ sum x)))) (define big (expt 2 15)) (func1 big) (func2 big 0)