One Thing After Another

The vector is one of Clojure’s most widely used—and useful—data structures. It’s just an ordered collection of items. Here, for example, is a vector of four numbers:

 [1 2 3 4]

Syntactically, our little four-element vector could not be simpler: it’s just four values surrounded by a pair of square brackets, sans commas. While our first vector contained only numbers, there is no requirement that all the items in a vector be of the same type. You can, for example, mix in strings:

 [1 ​"two"​ 3 ​"four"​]

Or Booleans:

 [true 3 ​"four"​ 5]

You can even nest vectors within vectors:

 [1 [true 3 ​"four"​ 5] 6]

And then do it again:

 [0 [1 [true 3 ​"four"​ 5] 6] 7]

You can, in fact, embed any Clojure value ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.