Clojure's Composite Data Structures (L16) Flashcards
What are Clojure’s 4 primary data structures?
Maps, vectors, lists, sets.
Clojure maps are equivalent to which Python datastructure?
Dictionaries.
How are empty maps defined?
{}
In practice, strings are used as Clojure keys.
False - keywords (:label) are often used as map keys.
Are Clojure’s :keywords case sensitive?
Yes.
Why are :keywords used over strings as map keys?
Faster internal lookups.
What Clojure function is used to perform map lookups?
get
Write 2 different ways in which the :key keyword is used to obtain a value from a map labelled m1.
(get m1 :key)
(:key m1)
What function is used to concisely retrieve values from nested maps?
get-in
What does the following line do?
(get jobs :bill “x”)
Returns :bill’s value in the jobs map, or returns “x” if not found.
Can non keyword keys also be used in the following manner?
(:bill jobs “x”)
No, only keywords may because as function invocations.
What does the following return?
(keys m1)
(vals m1)
A list of m1s keys and values, respectively.
What Clojure function can be used to check for the existence of a key in a map?
(contains? m1 :k)
When are commas used in Clojure?
Commas are considered to be whitespace. They may be used to make code slightly more readable.
Vectors in Clojure are 0-indexed sequences.
True.