📜  尾调用优化 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:41.591000             🧑  作者: Mango

代码示例1
(define (fact x)
  (if (= x 0) 1
      (* x (fact (- x 1)))))

(define (fact x)
  (define (fact-tail x accum)
    (if (= x 0) accum
        (fact-tail (- x 1) (* x accum))))
  (fact-tail x 1))