Scalar Types

4.1 Numbers

42                        ; Long
4.2                       ; Double
22/7                      ; Ratio (exact)
42N                       ; BigInt
3.14M                     ; BigDecimal
0xFF  2r1010  8r17  36rZZ ; hex, binary, octal, radix
1e3                       ; 1000.0
(/ 10 4)                  ; 5/2 (ratio)
(quot 10 4) (rem 10 4) (mod -7 3)   ; 2 2 2
(inc 5) (dec 5)           ; 6 4
(* 1000000000000 1000000000000)   ; ArithmeticException: integer overflow
(*' 1000000000000 1000000000000)  ; 1000000000000000000000000N (auto-promoting ops: +' -' *' inc' dec')
(Math/pow 2 10)           ; 1024.0
(abs -5)                  ; 5 (Clojure 1.11+)
(parse-long "42") (parse-double "3.14")   ; 42 3.14 (1.11+); nil on invalid input
(double 1/3) (int 3.9) (long 3.9) (bigdec 1/4)   ; 0.333 3 3 0.25M
(rand) (rand-int 10)
(even? 4) (odd? 3) (zero? 0) (pos? 1) (neg? -1) (number? 1) (int? 1) (ratio? 1/2)

4.2 Strings and Characters

"Hello"                               ; java.lang.String
(str "Hello, " "World" "!" 42)        ; concatenation and conversion
(count "hello")                       ; 5
(subs "hello world" 6)                ; "world"
(subs "hello" 1 3)                    ; "el"
(format "%s is %d years" "Ana" 30)    ; Java String.format
\a \A \newline \space \tab λ     ; characters
(char 65) (int \A)                    ; \A 65
(seq "abc")                           ; (\a \b \c): strings are seqable

4.3 Keywords and Symbols

:name                    ; keyword: evaluates to itself, fast equality, used as map keys
:user/name               ; namespaced keyword
::local                  ; auto-namespaced to the current ns (:user/local)
(keyword "status")       ; :status
(name :user/name)        ; "name"
(namespace :user/name)   ; "user"
(:name {:name "Ana"})    ; "Ana": keywords are functions that look themselves up

'my-symbol               ; symbol (names that refer to things)
(symbol "foo")           ; foo

4.4 Booleans and nil

true false nil
(if nil "yes" "no")      ; "no": only nil and false are falsey
(if 0 "yes" "no")        ; "yes": 0, "", and () are truthy
(nil? nil) (some? 1) (true? true) (boolean nil)   ; true true true false