Last active
December 16, 2015 06:48
-
-
Save sudowork/5393777 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
; 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