Skip to content

Instantly share code, notes, and snippets.

@vladimir-vg
Created February 14, 2011 10:46
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 vladimir-vg/825720 to your computer and use it in GitHub Desktop.
Save vladimir-vg/825720 to your computer and use it in GitHub Desktop.
;; simple
(define (fac acc n)
(if (= n 1)
acc
(fac (* acc n) (- n 1))))
;; not
(define (fac n)
(if (= n 1)
1
(* n (fac (- n 1)))))
;; both can be compiled with tail-call optimization.
;; first variant can be optimized more easily.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment