WhizzML Reference Manual
2.2 Literal expressions
2.2.1 Numbers
Constants of numeric types are expressed using the conventions and notation of Clojure for floating point values and integers
42
1.2e23
-2.1232E2
0x10 ;; hexadecimal 10 => 16
017 ;; octal 17 => 15
2r101 ;; binary 101 => 3
5r11 ;; base 5 11 => 6
2/3 ;; rational (/ 2 3) => 0.666666666
As seen in the examples, beyond the usual decimal and exponential literals, one can also write literal values using any base between 2 and 32 (with special notation for hexadecimal and octal) and use exact rational numbers, which behave as expected when arithmetically combined:
(+ 1/3 1/6 1/2) ;; => 1
2.2.2 Strings and booleans
Strings are quoted using " and must be single line ("a string", " another string.").
Booleans have two literal values, true and false .
2.2.3 Lists
Literal lists can be written enclosing a list of space-separated literals in square brackets ([]), e.g.
[0 1 2 3]
["A" -42 true] ;; lists can be heterogeneous
[["foo" 3] ["bar" 18]] ;; and nested
[] ;; this is the empty list
2.2.4 Sets
Set literals are written by specifiying the literal list of the set’s values, prepended by the symbol #
:
#[1 2 3]
#["a" true [1 2] {"a" 3}]
#[a b]
Duplicate values in the list are automatically removed from the resulting set and the order of the elements in the list is irrelevant.
(= #[1 2 3] #[2 1 3]) ;; => true
(= #[1 2 3] #[2 1 3 1 2]) ;; => true
2.2.5 Maps
Map literals are represented by enclosing a sequence of alternating keys and values in braces ({}):
{"key0" 3 "key1" 2} ;; a map with keys "key0" and "key1"
{"age" 74
"name" "Alan"
"scores" [1 0 0 2] ;; a map with
"address" {"street" "sesame" "number" 3}} ;; nested values
Values in map entries can have any type, and, like keys, can also include non-literal expressions:
(let (size 123
color "green"
outer-key "a thing"
k "key")
{outer-key {k size (str k 2) color}
(str outer-key 2) [size color]})
;; => {"a thing" {"key" 123 "key2" "green"}
;; "a thing2" [123 "green"]}
Although arbitrary expressions are allowed for the keys in map literals, they must eventually evaluate to string values.