Clojure: Basic Value Types (datatype)
Clojure is not typed. Variable doesn't have a type, value has type.
Basic Data Types
| name | example | Java type used |
|---|---|---|
| number | 18 | java.lang.Number |
| string | "some" | java.lang.String |
| boolean | true, false | java.lang.Boolean |
| char | \b, \c | java.lang.Character |
| keyword | :xyz, :bb | clojure.lang.keyword |
| nil | nil | null |
Basic Compound Data Types
| name | example | Java 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
- Newline (Line Feed; Unicode codepoint 10 in decimal) is
\newline - Tab character (Unicode codepoint 9 in decimal) is
\tab - Unicode character can be written as
\u4_digits_hex. For example, α is\u03b1(what about outside bmp?)
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: * + ! - _ ?