Created
November 28, 2010 10:23
-
-
Save buntine/718793 to your computer and use it in GitHub Desktop.
This file contains 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
; This function returns a closure. That is, the returned anonymous function | |
; saves a reference to the free variable "n". | |
(defn make-adder [n] | |
"Returns a function that sums a given value (m) with n." | |
(fn [m] | |
(+ n m))) | |
(def add-10 (make-adder 10)) | |
; When we invoke the function, rather than creating a new environment, it will | |
; reinstate the one that was active when it was defined. | |
(print (add-10 3)) ; Prints 13. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment