Working with primitive data types

In this recipe, we will review primitive data types that Clojure supports and a few functions that manipulate these types. Here, we will review the following:

  • Using numbers
  • Using strings and characters
  • Using booleans and nil
  • Using keywords and symbols

Getting ready

You only need REPL, as described in the previous recipe, and no additional libraries. Start REPL so that you can review the sample code of primitive types immediately in this recipe.

How to do it...

Let's start with numbers in Clojure data types.

Using numbers

The + function returns the sum of numbers. You can specify any number of numbers as arguments:

(+ 1 2) 
;;=> 3 
(+ 1 2 3) 
;;=> 6 
(+ 1.2 3.5) 
;;=> 4.7 

The - function subtracts the numbers. If a single argument ...

Get Clojure Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.