Clarify keywords, symbols, maps, sets

This commit is contained in:
Micah Martin and Colin Jones 2013-03-04 17:30:00 -06:00
parent d275ab804d
commit 28bf698566
5 changed files with 24 additions and 13 deletions

View File

@ -1,5 +1,8 @@
Concepts / Language Features Concepts / Language Features
===== =====
Quoting
new record syntax new record syntax
Agents Agents
Vars Vars

View File

@ -5,6 +5,9 @@
false false
true true
true true
false
"foo"
"foo"
3]}] 3]}]
["02_lists" {"__" [1 2 3 4 5 ["02_lists" {"__" [1 2 3 4 5
@ -31,15 +34,14 @@
[:butter :and] [:butter :and]
3]}] 3]}]
["04_sets" {"__" [nil ["04_sets" {"__" [[3]
3 3
#{1 2 3 4 5} #{1 2 3 4 5}
#{1 2 3 4 5} #{1 2 3 4 5}
#{2 3} #{2 3}
#{1 4}]}] #{1 4}]}]
["05_maps" {"__" [{} ["05_maps" {"__" [:b 2
0
1 1
2 2
2 2

View File

@ -20,5 +20,14 @@
"Something is not equal to nothing" "Something is not equal to nothing"
(= __ (not (= 1 nil))) (= __ (not (= 1 nil)))
"Strings, and keywords, and symbols: oh my!"
(= __ (= "foo" :foo 'foo))
"Make a keyword with your keyboard"
(= :foo (keyword __))
"Symbolism is all around us"
(= 'foo (symbol __))
"When things cannot be equal, they must be different" "When things cannot be equal, they must be different"
(not= :fill-in-the-blank __)) (not= :fill-in-the-blank __))

View File

@ -1,11 +1,11 @@
(meditations (meditations
"You can create a set in two ways" "You can create a set by converting another collection"
(= #{} (set __)) (= #{3} (set __))
"They are another important data structure in clojure" "Counting them is like counting other collections"
(= __ (count #{1 2 3})) (= __ (count #{1 2 3}))
"Remember that a set is a 'set'" "Remember that a set is a *mathematical* set"
(= __ (set '(1 1 2 2 3 3 4 4 5 5))) (= __ (set '(1 1 2 2 3 3 4 4 5 5)))
"You can ask clojure for the union of two sets" "You can ask clojure for the union of two sets"

View File

@ -1,9 +1,6 @@
(meditations (meditations
"There are two ways to create maps" "Don't get lost when creating a map"
(= __ (hash-map)) (= {:a 1 :b 2} (hash-map :a 1 __ __))
"Maps in clojure associate keys with values"
(= __ (count (hash-map)))
"A value must be supplied for each key" "A value must be supplied for each key"
(= {:a 1} (hash-map :a __)) (= {:a 1} (hash-map :a __))
@ -14,7 +11,7 @@
"You can look up the value for a given key" "You can look up the value for a given key"
(= __ (get {:a 1 :b 2} :b)) (= __ (get {:a 1 :b 2} :b))
"Maps can be used as lookup functions" "Maps can be used as functions to do lookups"
(= __ ({:a 1 :b 2} :a)) (= __ ({:a 1 :b 2} :a))
"And so can keywords" "And so can keywords"