Define Function
Write a function which returns a personalized greeting. (= (__ “Dave”) “Hello, Dave!”)
1
|
|
or
“#(str "Hello, ” % “!”)"
Filter
1
|
|
returns ‘(6 7)
Local Bindings
Clojure lets you give local names to values using the special let-form.
Sample1
1
|
|
In Java something like:
1 2 |
|
Sample2
1
|
|
In Java something like:
1 2 |
|
Recursion
A recursive function is a function which calls itself. This is one of the fundamental techniques used in functional programming.
1 2 3 4 5 6 |
|
Rearranging Code “->” vs “->>”
These two lines are the same
1 2 3 |
|
I like this explaination:
;; let's compare thread first (->) and thread last ( ->> )
user=> (macroexpand '(-> 0 (+ 1) (+ 2) (+ 3)))
(+ (+ (+ 0 1) 2) 3)
user=> (macroexpand '(->> 0 (+ 1) (+ 2) (+ 3)))
(+ 3 (+ 2 (+ 1 0)))
Loop and recur
(loop [bindings] exprs)
1 2 3 4 5 6 7 8 |
|