Created
November 28, 2010 10:26
-
-
Save buntine/718796 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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