Clojure - Data Types

Clojure offers a wide variety of built-in data types.
Following is a list of data types which are defined in Clojure.
Integers − Following are the representation of Integers available in Clojure.

Decimal Integers (Short, Long and Int) − These are used to represent whole numbers. For example, 1234.
Octal Numbers − These are used to represent numbers in octal representation. For example, 012.
Hexadecimal Numbers − These are used to represent numbers in representation. For example, 0xff.
Radix Numbers − These are used to represent numbers in radix representation. For example, 2r1111 where the radix is an integer between 2 and 36, inclusive.

Integers − Following are the representation of Integers available in Clojure.
Decimal Integers (Short, Long and Int) − These are used to represent whole numbers. For example, 1234.
Decimal Integers (Short, Long and Int) − These are used to represent whole numbers. For example, 1234.
Octal Numbers − These are used to represent numbers in octal representation. For example, 012.
Octal Numbers − These are used to represent numbers in octal representation. For example, 012.
Hexadecimal Numbers − These are used to represent numbers in representation. For example, 0xff.
Hexadecimal Numbers − These are used to represent numbers in representation. For example, 0xff.
Radix Numbers − These are used to represent numbers in radix representation. For example, 2r1111 where the radix is an integer between 2 and 36, inclusive.
Radix Numbers − These are used to represent numbers in radix representation. For example, 2r1111 where the radix is an integer between 2 and 36, inclusive.
Floating point

The default is used to represent 32-bit floating point numbers. For example, 12.34.
The other representation is the scientific notation. For example, 1.35e-12.


Floating point
The default is used to represent 32-bit floating point numbers. For example, 12.34.
The default is used to represent 32-bit floating point numbers. For example, 12.34.
The other representation is the scientific notation. For example, 1.35e-12.
The other representation is the scientific notation. For example, 1.35e-12.
char − This defines a single character literal. Characters are defined with the backlash symbol. For example, /e.
char − This defines a single character literal. Characters are defined with the backlash symbol. For example, /e.
Boolean − This represents a Boolean value, which can either be true or false.
Boolean − This represents a Boolean value, which can either be true or false.
String − These are text literals which are represented in the form of chain of characters. For example, “Hello World”.
String − These are text literals which are represented in the form of chain of characters. For example, “Hello World”.
Nil − This is used to represent a NULL value in Clojure.
Nil − This is used to represent a NULL value in Clojure.
Atom − Atoms provide a way to manage shared, synchronous, independent state. They are a reference type like refs and vars.
Atom − Atoms provide a way to manage shared, synchronous, independent state. They are a reference type like refs and vars.
Since all of the datatypes in Clojure are inherited from Java, the bounded values are the same as in Java programming language. The following table shows the maximum allowed values for the numerical and decimal literals.
In addition to the primitive types, the following object types (sometimes referred to as wrapper types) are allowed.
The following program shows a consolidated clojure code to demonstrate the data types in Clojure.
(ns clojure.examples.hello
   (:gen-class))

;; This program displays Hello World
(defn Example []
   ;; The below code declares a integer variable
   (def x 1)
   
   ;; The below code declares a float variable
   (def y 1.25)
   
   ;; The below code declares a string variable
   (def str1 "Hello")
   (println x)
   (println y)
   (println str1))
(Example)
The above program produces the following output.
1
1.25
Hello

 Print
 Add Notes
 Bookmark this page