A Toolkit of Functions

Along with the literal syntax there is also a function that manufactures vectors, called, appropriately enough, vector. The vector function takes any number of any kind of argument and wraps a vector around those arguments:

 ;; The same as [true 3 "four" 5]
 
 (vector true 3 ​"four"​ 5)
 
 ;; The same as []
 
 (vector)

However you conjure it up, once you have a vector you’ll want to do stuff with it. Fortunately, Clojure provides all sorts of useful functions to go with your vectors. For example, if you’re interested in how many items are hiding inside your vector you can use our old friend count:

 (​def​ novels [​"Emma"​ ​"Coma"​ ​"War and Peace"​])
 
 (count novels) ​; Returns 3.

You can get at the first item ...

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.