Clojure: Basic Value Types (datatype)

By Xah Lee. Date: . Last updated: .

Clojure is not typed. Variable doesn't have a type, value has type.

Basic Data Types

Clojure Basic Data Types
nameexampleJava type used
number18java.lang.Number
string"some"java.lang.String
booleantrue, falsejava.lang.Boolean
char\b, \cjava.lang.Character
keyword:xyz, :bbclojure.lang.keyword
nilnilnull

Basic Compound Data Types

Clojure Basic Compound Data Types
nameexampleJava type used
list'(3 "e" 7)
vector[8 2 "h"]
map{:mary 13 :john 20}java.util.Map
set#{9 2 4}java.util.Set

Clojure Char Data Type Literal

Keyword

“keyword” is a primitive datatype in Clojure. Keywords are symbolic identifiers. Usually used as keys for hash table. It's like Ruby's “symbol”.

keywords starts with a :, like this: :abc

To convert a string to keyword, use keyword function.

clojure.core/keyword

keyword is also a function. The work on hasmap and return the corresponding value.

Symbol

Symbols are identifiers, but unlike identifier in other languages, Clojure's symbol can remain in a unevaluated form.

(Clojure's symbol is the same as other lisp's symbol.)

symbols can include these characters: * + ! - _ ?