May 2018
Beginner to intermediate
290 pages
6h 43m
English
Although so far we have limited ourselves to destructuring vectors, all of the tricks we’ve seen so far will work with any of Clojure’s sequential data types. Thus if we switch our names from a vector to a list:
| | (def artist-list '(:monet :austen :beethoven :dickinson)) |
the destructuring stays exactly the same:
| | (let [[painter novelist composer] artist-list] |
| | (println "The painter is" painter) |
| | (println "The novelist is" novelist) |
| | (println "The composer is" composer)) |
Note especially that even when we’re destructuring a list, we continue to use square brackets around our template. The left side of the binding equation remains [painter novelist composer]. In this context you can think of those square brackets ...
Read now
Unlock full access