Skip to content

Instantly share code, notes, and snippets.

@buntine
Created November 28, 2010 10:23
Show Gist options
  • Save buntine/718793 to your computer and use it in GitHub Desktop.
Save buntine/718793 to your computer and use it in GitHub Desktop.
; 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