Skip to content

Instantly share code, notes, and snippets.

@buntine
Created November 28, 2010 10:26
Show Gist options
  • Save buntine/718796 to your computer and use it in GitHub Desktop.
Save buntine/718796 to your computer and use it in GitHub Desktop.
; letfn is a Clojure macro that allows for mutually recursive functions.
; In some lisps, letfn (or letrec) will expand to a lambda expression.
(letfn [(fact-helper [total n]
(if (<= n 1)
total
(fact-helper (* n total) (- n 1))))]
(defn fact [n]
(fact-helper 1 n)))
(fact 5) ; 120
(fact-helper 1 5) ; Error: Unbound reference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment