adding sequence comprehensions and a 3-argument equality

master
Colin Jones 14 years ago
parent 1c006a6fc9
commit 937bbfd34b

@ -1,9 +1,12 @@
(meditations
"We shall contemplate truth by testing reality, via equality."
(= true false)
"To understand reality, we must compare our expectations against reality."
(= 0 (+ 1 1))
"Sometimes we will ask you to fill in the values"
(= __ (+ 1 1)))
(= __ (+ 1 1))
"You can test equality of many things"
(= (+ 3 4) __ (+ 2 _)))

@ -0,0 +1,32 @@
(meditations
"Sequence comprehensions can bind each element in turn to a symbol"
(= __
(for [index (range 6)]
index))
"They can easily emulate mapping"
(= '(0 1 4 9 16 25)
(map (fn [index] (* index index))
(range 6))
(for [index (range 6)]
__))
"And also filtering"
(= '(1 3 5 7 9)
(filter odd? (range 10))
(for [index __ :when (odd? index)]
index))
"And they trivially allow combinations of the two transformations"
(= '(1 9 25 49 81)
(map (fn [index] (* index index))
(filter odd? (range 10)))
(for [index (range 10) :when __]
__))
"More complex transformations can be formed with multiple binding forms"
(= [[:top :left] [:top :middle] [:top :right]
[:middle :left] [:middle :middle] [:middle :right]
[:bottom :left] [:bottom :middle] [:bottom :right]]
(for [row [:top :middle :bottom] column [:left :middle :right]]
__)))

@ -20,4 +20,5 @@
(load "about_conditionals")
(load "about_higher_order_functions")
(load "about_runtime_polymorphism")
(load "about_sequence_comprehensions")
(println "You have acheived clojure enlightenment. Namaste.")

Loading…
Cancel
Save