Avoid nil answer, but allow it to fail if it's wrong. Fixes #6.
This commit is contained in:
parent
9c947e7ac7
commit
1648d9e94a
@ -1,6 +1,6 @@
|
|||||||
(meditations
|
(meditations
|
||||||
"Lists can be expressed by function or a quoted form"
|
"Lists can be expressed by function or a quoted form"
|
||||||
(= '(__) (list 1 2 3 4 5))
|
(= '(__ __ __ __ __) (list 1 2 3 4 5))
|
||||||
|
|
||||||
"They are Clojure seqs (sequences), so they allow access to the first"
|
"They are Clojure seqs (sequences), so they allow access to the first"
|
||||||
(= __ (first '(1 2 3 4 5)))
|
(= __ (first '(1 2 3 4 5)))
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
(= __ ({2006 "Torino" 2010 "Vancouver" 2014 "Sochi"} 2010))
|
(= __ ({2006 "Torino" 2010 "Vancouver" 2014 "Sochi"} 2010))
|
||||||
|
|
||||||
"You may not be able to find an entry for a key"
|
"You may not be able to find an entry for a key"
|
||||||
(= __ (get {:a 1 :b 2} :c))
|
(= __ (get {:a 1 :b 2} :c :key-not-found))
|
||||||
|
|
||||||
"You can find out if a key is present"
|
"You can find out if a key is present"
|
||||||
(= __ (contains? {:a nil :b nil} :b))
|
(= __ (contains? {:a nil :b nil} :b))
|
||||||
|
@ -11,16 +11,16 @@
|
|||||||
false
|
false
|
||||||
6/3
|
6/3
|
||||||
3]}
|
3]}
|
||||||
"lists" {"__" ["1 2 3 4 5"
|
"lists" {"__" [1 2 3 4 5
|
||||||
1
|
1
|
||||||
[2 3 4 5]
|
[2 3 4 5]
|
||||||
"()"
|
()
|
||||||
[:a :b :c :d :e]
|
[:a :b :c :d :e]
|
||||||
[0 :a :b :c :d :e]
|
[0 :a :b :c :d :e]
|
||||||
:a
|
:a
|
||||||
[:b :c :d :e]
|
[:b :c :d :e]
|
||||||
"\"No dice!\""
|
"No dice!"
|
||||||
"()"]}
|
()]}
|
||||||
"vectors" {"__" [1
|
"vectors" {"__" [1
|
||||||
[]
|
[]
|
||||||
[1]
|
[1]
|
||||||
@ -43,14 +43,14 @@
|
|||||||
2
|
2
|
||||||
1
|
1
|
||||||
1
|
1
|
||||||
"\"Vancouver\""
|
"Vancouver"
|
||||||
nil
|
:key-not-found
|
||||||
true
|
true
|
||||||
false
|
false
|
||||||
"\"February\""
|
"February"
|
||||||
1 "\"January\""
|
1 "January"
|
||||||
2006 2010 2014
|
2006 2010 2014
|
||||||
"\"Vancouver\""]}
|
"Vancouver"]}
|
||||||
"functions" {"__" [20
|
"functions" {"__" [20
|
||||||
10 5
|
10 5
|
||||||
30 2
|
30 2
|
||||||
@ -67,7 +67,7 @@
|
|||||||
"higher_order_functions" {"__" [4 8 12
|
"higher_order_functions" {"__" [4 8 12
|
||||||
'(* x x)
|
'(* x x)
|
||||||
[false false true false false]
|
[false false true false false]
|
||||||
"()"
|
()
|
||||||
true
|
true
|
||||||
'(< x 31)
|
'(< x 31)
|
||||||
'(* 10 x) '(< x 4)
|
'(* 10 x) '(< x 4)
|
||||||
@ -77,9 +77,9 @@
|
|||||||
"runtime_polymorphism" {"__" ['(str (:name a) " eats veggies.")
|
"runtime_polymorphism" {"__" ['(str (:name a) " eats veggies.")
|
||||||
'(str (:name a) " eats animals.")
|
'(str (:name a) " eats animals.")
|
||||||
'(str "I don't know what " (:name a) " eats.")
|
'(str "I don't know what " (:name a) " eats.")
|
||||||
"\"Hello World!\""
|
"Hello World!"
|
||||||
"\"Hello, you silly world.\""
|
"Hello, you silly world."
|
||||||
"\"Hello to this group: Peter, Paul, Mary!\"" ]}
|
"Hello to this group: Peter, Paul, Mary!" ]}
|
||||||
"sequence_comprehensions" {"__" [[0 1 2 3 4 5]
|
"sequence_comprehensions" {"__" [[0 1 2 3 4 5]
|
||||||
'(* index index)
|
'(* index index)
|
||||||
'(range 10)
|
'(range 10)
|
||||||
@ -93,7 +93,7 @@
|
|||||||
4
|
4
|
||||||
8]
|
8]
|
||||||
"___" ['(complement nil?)
|
"___" ['(complement nil?)
|
||||||
"multiply-by-5"
|
'multiply-by-5
|
||||||
'(comp dec square)]}
|
'(comp dec square)]}
|
||||||
"recursion" {"__" [true 'acc
|
"recursion" {"__" [true 'acc
|
||||||
'(loop [n n acc 1]
|
'(loop [n n acc 1]
|
||||||
@ -101,7 +101,7 @@
|
|||||||
acc
|
acc
|
||||||
(recur (dec n) (* acc n))))]
|
(recur (dec n) (* acc n))))]
|
||||||
"___" ['not]}
|
"___" ['not]}
|
||||||
"destructuring" {"__" ["\":bar:foo\""
|
"destructuring" {"__" [":bar:foo"
|
||||||
'(format (str "First comes %s, "
|
'(format (str "First comes %s, "
|
||||||
"then comes %s, "
|
"then comes %s, "
|
||||||
"then comes %s with the baby carriage")
|
"then comes %s with the baby carriage")
|
||||||
@ -124,10 +124,10 @@
|
|||||||
(str fname " " lname ", "
|
(str fname " " lname ", "
|
||||||
street-address ", " city ", " state))
|
street-address ", " city ", " state))
|
||||||
]}
|
]}
|
||||||
"refs" {"__" ["\"hello\""
|
"refs" {"__" ["hello"
|
||||||
"\"hello\""
|
"hello"
|
||||||
"\"better\""
|
"better"
|
||||||
"\"better!!!\""
|
"better!!!"
|
||||||
'(dosync (ref-set the-world 0))
|
'(dosync (ref-set the-world 0))
|
||||||
]
|
]
|
||||||
"___" ['(comp exclamator exclamator exclamator)
|
"___" ['(comp exclamator exclamator exclamator)
|
||||||
@ -140,7 +140,7 @@
|
|||||||
(butlast
|
(butlast
|
||||||
(interleave
|
(interleave
|
||||||
unreplaced-texts
|
unreplaced-texts
|
||||||
(concat replacements (repeat k)))))))
|
(concat (map pr-str replacements) (repeat k)))))))
|
||||||
|
|
||||||
(defn koan-text [koan]
|
(defn koan-text [koan]
|
||||||
(slurp (str "src/koans/" koan ".clj")))
|
(slurp (str "src/koans/" koan ".clj")))
|
||||||
|
Loading…
Reference in New Issue
Block a user