Skip to content

Instantly share code, notes, and snippets.

@sudowork
Last active December 16, 2015 06:48
Show Gist options
  • Save sudowork/5393777 to your computer and use it in GitHub Desktop.
Save sudowork/5393777 to your computer and use it in GitHub Desktop.
; defining a function to square a number
user=> (defn square [x] (* x x))
#'user/square
user=> (square 3)
9
; now using an anonymous function
user=> (def square2 (fn [x] (* x x)))
#'user/square2
user=> (square2 3)
9
; some more sugar for anonymous functions
user=> (#(* % %) 3) ; square
9
user=> (#(+ % (* 2 %2)) 1 3) ; 1*x + 2*y
7
user=> (+ 1 (* 2 3))
7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment