Vectors and Keywords

Keywords are used much as we would use a keyword in Ruby or an enum in Java, and are prepended with a colon.

 => :foo
 :foo

Vectors give us fast positional access to their elements. They can be created by placing the elements of the vector inside of square brackets. We create a vector and name it some-keywords in the following snippet.

 => (def some-keywords [:foo :bar :baz])
 #'matters/some-keywords

We can use first to get the first element of a vector.

 => (first some-keywords)
 :foo

In the preceding example, the actions of the reader take place behind the scenes, as part of the REPL. Let’s make things a bit more explicit by using read-string. This takes a string directly and reads it. Here, we’re using it to read ...

Get Functional Programming: A PragPub Anthology 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.