O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required