O'Reilly logo

Clojure Programming Cookbook by Nicolas Modrzyk, Makoto Hashimoto

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

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

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