Skip to content

Instantly share code, notes, and snippets.

@chomado
Created February 24, 2014 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chomado/9195731 to your computer and use it in GitHub Desktop.
Save chomado/9195731 to your computer and use it in GitHub Desktop.
;;; 普通の再帰
(define (factorial n)
(if (= n 1)
1
(* n (factorial (- n 1)))))
;;; 末尾再帰
(define (factorial n)
(fact-iter 1 1 n))
(define (fact-iter product counter max-count)
(if (> counter max-count)
product
(fact-iter (* counter product)
(+ counter 1)
max-count)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment