03 Core Functions

The core library holds every function whose name has no prefix, such as map, +, and str. Prefixed names belong to other libraries, such as time/now. See DUST for source notation, evaluation, and special forms, and the Function Index for all callable entries.

Ordinary function arguments evaluate before the call. Functions can be passed as values and called through apply. This page covers function calls, equality, and booleans; the rest of the core library is grouped by area:

3.1. apply

Function

(apply function arguments) → value

Calls a function value with the elements of a list as its arguments.

Both operands are evaluated before the call. The first must produce an ordinary function, and the second must produce a list or null. The function is checked first, so (apply true false) gives expected a function value. A null argument list supplies no arguments. A string naming a function is not a function value. Special forms and macros cannot be called through apply. The list elements are passed as values, without evaluating them again as source.

DUST
(apply :+ [1 2])
=
DUST
(apply (if true :+ :*) [2 3])
=
DUST
(apply "+" [1 2])
=
DUST Result
#err <expected function>
DUST
(let [increment (fn [x] (+ 1 x))]
  (apply increment [4]))
→
Canonical DUST
(let [increment (fn [x] (+ 1 x))] (apply increment [4]))
=
DUST
(errors/message (apply true false))
(errors/message (apply true [1]))
(errors/message (apply (fn [x] x) 5))
(errors/message (let [f (fn [a b] (apply a b))] (f true false)))
(errors/message (reduce (fn [acc x] (apply acc x)) true [false []]))
=
DUST Result
"expected a function value"
"expected a function value"
"expected a list or null"
"expected a function value"
"expected a function value"

3.2. =

Function

(= x) → boolean
(= x y) → boolean
(= x y more*) → boolean

Returns true if all supplied values are equal, otherwise false.

With one argument, returns true. With no arguments, produces an arity error.

With two or more arguments, compares adjacent values from left to right. The first unequal pair returns false without comparing later pairs. If every pair is equal, returns true.

Each compared pair must have the same type. A type mismatch in a pair being compared produces #err <mismatch type>. Types are not checked in advance across all arguments. For example, ( 1 2 "2")= returns false, but ( 1 1 "1")= produces a type error. Integers and floats are different types, so ( 1 1.0)= produces a type error.

= is an ordinary function. Its argument expressions are evaluated before comparison begins. Short-circuiting skips comparisons, not argument evaluation. Thus ( 1 2 (/ 1 0))= produces a division-by-zero error.

  • Numbers of the same type compare by value.
  • Links compare their signed 64-bit payloads; a link and an integer have different types.
  • Lists compare positionally.
  • Maps compare keys and values independently of member order.
  • Functions compare by identity.
DUST
[(= 1) (= null) (= [1 2]) (= (fn []))
 (= 1 1) (= 1 2)
 (= 1 1 1) (= 1 1 2) (= 1 2 1)
 (= 1 2 "2") (= 1 1 2 null)
 (= null null null) (= [1] [1] [1])]
→
Canonical DUST
(= 1)
(= null)
(= [1 2])
(= (fn []))
(= 1 1)
(= 1 2)
(= 1 1 1)
(= 1 1 2)
(= 1 2 1)
(= 1 2 "2")
(= 1 1 2 null)
(= null null null)
(= [1] [1] [1])
=
DUST Result
true
true
true
true
true
false
true
false
false
false
false
true
true
DUST
(=)
=
DUST Result
#err <argument missing>
DUST
(= 1 1 "1")
=
DUST Result
#err <mismatch type>
DUST
(= 1 2 (/ 1 0))
=
DUST Result
#err {<division integer zero>
      message "division by zero"}
DUST
(= (/ 1 0))
=
DUST Result
#err {<division integer zero>
      message "division by zero"}
DUST
(= 1 1.0)
=
DUST Result
#err <mismatch type>
DUST
(= "hello" "hello")
=
DUST
(= [1 2] [1 2])
=
DUST
(= [1 2] [2 1])
=
DUST
(= {x 1} {x 1})
=
DUST
(= {a 1 b 2} {b 2 a 1})
→
Canonical DUST
(= {a 1 b 2} {a 1 b 2})
=
DUST
(= {a "b"} {a "b" c null})
=
DUST
(= {<active>} {active true})
→
Canonical DUST
(= <active> <active>)
=
DUST
(= {<!active>} {active false})
→
Canonical DUST
(= <!active> <!active>)
=
DUST
(= {<!active>} {})
→
Canonical DUST
(= <!active> {})
=
DUST
(= `[] [])
=
DUST
(= `[1 2] [1 2])
=
DUST
(let [a {x 1}
      b {x 1}
      c a]
  (= a b))
→
Canonical DUST
(let [a {x 1} b {x 1} c a] (= a b))
=
DUST
(let [a {x 1}
      b {x 1}
      c a]
  (= a c))
→
Canonical DUST
(let [a {x 1} b {x 1} c a] (= a c))
=
DUST
(let [a {x 1} b {x 1} c a] (patch a {x 2}))
=
DUST
(let [a {x 1} b {x 1} c a] (patch a {x 2}) (= a b))
=
DUST
(let [a {x 1} b {x 1} c a] (patch a {x 2}) (= a c))
=
DUST
(let [f (fn [x] x)
      g f
      h (fn [x] x)]
  (= f g))
→
Canonical DUST
(let [f (fn [x] x) g f h (fn [x] x)] (= f g))
=
DUST
(let [f (fn [x] x)
      g f
      h (fn [x] x)]
  (= f h))
→
Canonical DUST
(let [f (fn [x] x) g f h (fn [x] x)] (= f h))
=
DUST
(let [f (fn [x] x)
      g f
      h (fn [x] x)]
  (= f "a"))
→
Canonical DUST
(let [f (fn [x] x) g f h (fn [x] x)] (= f "a"))
=
DUST Result
#err <mismatch type>
DUST
(let [f (fn [x] x)
      g f
      h (fn [x] x)]
  (= [f] [g]))
→
Canonical DUST
(let [f (fn [x] x) g f h (fn [x] x)] (= [f] [g]))
=
DUST
(let [f (fn [x] x)
      g f
      h (fn [x] x)]
  (= [f] [h]))
→
Canonical DUST
(let [f (fn [x] x) g f h (fn [x] x)] (= [f] [h]))
=
DUST
(let [f (fn [x] x)
      g f
      h (fn [x] x)]
  (= {callback f} {callback g}))
→
Canonical DUST
(let [f (fn [x] x) g f h (fn [x] x)] (= {callback f} {callback g}))
=

3.3. ==

Function

(== x) → boolean
(== x y) → boolean
(== x y more*) → boolean

Is another name for the equality function. It takes the same arguments and returns the same results and errors.

3.4. not

Function

(not value) → boolean

Returns true if value is null or false, otherwise false.

An error argument is the result, as for other calls. An error is falsey, so (if (not (f)) a b) selects b when (f) returns an error. Use error? to select a branch for an error.

DUST
(not (/ 1 0))
(if (not (/ 1 0)) "then" "else")
(if (error? (/ 1 0)) "error" "value")
=
DUST Result
#err {<division integer zero>
      message "division by zero"}
"else"
"error"
DUST
(not true)
=
DUST
(not false)
=
DUST
(not null)
=
DUST
(not 0)
=
DUST
(not [])
=

3.5. Collections

These core functions build, read, and transform lists and maps. Functions that change a collection change it in place and return it; collections/copy makes a copy to change instead. They are part of the core library; see DUST for source notation, evaluation, and special forms.

3.5.1. Collection Functions

Pointers can be used where these list functions accept a list. Pointer segments are strings for keys and integers for indices.

Function Pointer behavior
count, empty? Count segments or test for no segments
first, second, last, nth Return one segment value
rest, slice, take, drop Return a pointer containing the selected segments
concat Return a pointer when the first argument is a pointer; list-first concatenation returns a list
map, filter, reduce, some, every?, take-while, drop-while Iterate segment values and return the usual list-function result

Pointers are values that do not change, so the functions that change a list, such as lists/append, lists/reverse, and sort, reject pointers with #err <mismatch type>.

Unless stated otherwise, list operations that make a new list accept null as an empty list, and map operations that make a new map accept null as an empty map. Functions that change a collection require a target of the stated collection type, not null. Map keys are strings. Callbacks receive existing values without copying. Their side effects are not undone.

3.5.1.1. map

Function

(map f xs) → list
(map f xs lists*) → list

Returns a list of the results of applying f to corresponding elements of xs and any additional lists.

The function receives one argument from each input list. Calls occur in sequence order and stop when the shortest input is exhausted. The result is built eagerly. Inputs are lists, pointers, bytes, bitsets, or null, with null treated as an empty list. Bytes supply their byte values, the integers 0 to 255, and the result is a list.

DUST
[(map (fn [x] (strings/case "upper" x)) ["ada" "straße" ""])
 (map :+ [1 2] [10 20 30])
 (map :+ [1 2] [10] [100 200])
 (map :+ [1 2] [10 20] [100] [1000 2000])
 (map (fn [x] (strings/case "upper" x)) [])
 (map (fn [x] (strings/case "upper" x)) null)
 (map :+ [1] null)
 (map (fn [x] [x]) [1 2])]
→
Canonical DUST
(map (fn [x] (strings/case "upper" x)) ["ada" "straße" ""])
(map :+ [1 2] [10 20 30])
(map :+ [1 2] [10] [100 200])
(map :+ [1 2] [10 20] [100] [1000 2000])
(map (fn [x] (strings/case "upper" x)) [])
(map (fn [x] (strings/case "upper" x)) null)
(map :+ [1] null)
(map (fn [x] [x]) [1 2])
=
DUST Result
[["ADA" "STRASSE" ""] [11 22] [111] [1111] [] [] [] [[1] [2]]]
DUST
(reduce (fn [sum x] (+ sum x)) 0 #b64 "F8gHWw==")
(map (fn [x] (+ x 1)) #b64 "F8gHWw==")
(map (fn [x] x) #b64 "")
(map (fn [x y] (+ x y)) #b64 "AQI=" [10 20 30])
(map (fn [x] (str x)) #b64 "AAE=")
(lists/filter (fn [x] (> x 50)) #b64 "F8gHWw==")
(for [x #b64 "AQID"] (* x 2))
(lists/concat #b64 "AQI=" [3])
(bytes/of (map (fn [x] (- 255 x)) #b64 "AP8="))
=
DUST Result
321
[24 201 8 92]
[]
[11 22]
["0" "1"]
[200 91]
[2 4 6]
[1 2 3]
#b64 "/wA="
DUST
(map (fn [x] (strings/case "upper" x)))
=
DUST Result
#err <list missing>
DUST
(map "upper" ["ada"])
=
DUST Result
#err <expected function>
DUST
(map (fn [x] (strings/case "upper" x)) "ada")
=
DUST Result
#err <mismatch type>
DUST
(map (fn [x] (/ 1 x)) [1 0])
=
DUST Result
1.0
#err <division integer zero>

3.5.1.2. reduce

Function

(reduce function initial list) → value

Starts with initial and calls function with the accumulator and each list element, in list order. Each call's result becomes the next accumulator. Returns the final accumulator. An empty list or null returns initial without calling the function. The first argument must be an ordinary function value and the third must be a list, pointer, bytes, or null. Errors stop reduction immediately: a call that returns an #err value ends the reduction, and that value is the result.

DUST
(reduce :+ 0 [1 2 3])
(reduce :- 10 [1 2 3])
(reduce (fn [acc x] (strings/join [acc x] "")) "" ["a" "b" "c"])
(reduce :+ 9007199254740993 [1 1])
=
DUST Result
6
4
"abc"
9007199254740995
DUST
(reduce (fn [acc x] (/ 1 0)) "seed" [])
(reduce :+ false null)
(reduce :+ null [])
=
DUST Result
"seed"
false
null
DUST
(reduce "+" 0 [])
=
DUST Result
#err <expected function>
DUST
(reduce :+ 0 "abc")
=
DUST Result
#err <mismatch type>
DUST
(reduce :+ 0)
=
DUST Result
#err <arity mismatch>
DUST
(reduce (fn [acc x] (/ acc x)) 12.0 [2.0 0.0 3.0])
=
DUST Result
#err <division float zero>
DUST
(reduce (fn [x] x) 0 [1])
=
DUST Result
#err <arity mismatch>
DUST
(reduce "+" (/ 1 0) [])
=
DUST Result
#err {<division integer zero>
      message "division by zero"}

3.5.1.3. patch

Function

(patch map changes*) → map

Applies JSON Merge Patch member semantics to map in place and returns the same map. All arguments must be maps, checked before any patch is applied. With no changes maps, returns map unchanged.

Applies changes maps from left to right. Within each map, processes keys in ascending Unicode order:

  • null removes the member. A missing member is a no-op.
  • A map recursively patches the corresponding map. A missing or non-map destination is replaced with an empty map first.
  • Any other value replaces the member without copying. Lists are replaced whole, not patched element by element.

Omitted members are unchanged. Nested patch maps are traversed, not installed by reference. Collects the keys of each patch map before visiting its members, then reads each value when its key is processed, ignoring keys since removed. Patch sources that alias the target observe earlier mutations. Encountering a cycle through patch maps produces #err <invalid value> before applying the cyclic member. Earlier writes are not undone.

(patch {} a b) merges into a fresh map, and (patch (collections/copy m shallow) changes) into a copy of m. Neither is a deep copy of the changes: null-valued members are omitted and list values are shared. Use put to store null as a value.

DUST
(let [m {a 1}] [(patch m {a 2}) m])
(patch {} {a {b 1}} {a {c 2}})
(patch {a 1} {a null})
=
DUST Result
[[{a 2} {a 2}] {a {b 1 c 2}} {}]
DUST
(patch {items ["a" "b" "c"] keep 1} {items ["x" null] missing null})
(patch {a 1} {a {b 2 gone null}})
(patch {a {b 1 c 2}} {a {b null}})
=
DUST Result
{items ["x" null]
 keep 1}
{a {b 2}}
{a {c 2}}

3.5.1.4. seq

Function

(seq value) → list

Returns the elements of a list, pointer, Bytes or Bitset as a list. A Bitset supplies its members in ascending order. null gives an empty list.

DUST
(seq #bitset [1 3 5])
(seq #bitset [])
=
DUST Result
[[1 3 5] []]

3.5.1.5. count

Function

(count collection) → integer

Returns the number of list elements, pointer segments, map members, Unicode string code points, or bytes of a Bytes value. For null, returns zero.

DUST
(count ["a" "b"])
(count {a 1 b 2})
(count null)
=
DUST
(count #b64 "F8gHWw==")
(count #b64 "")
(count #b64 "w6k=")
(empty? #b64 "")
(empty? #b64 "AA==")
=
DUST Result
4
0
2
true
false

For strings, count returns the number of Unicode code points. For example, é猫 has two code points. The letter e followed by a combining acute accent also counts as two code points.

DUST
(count "é猫")
(count "🙂")
(count "é")
(count "")
=
DUST Result
2
1
2
0

A failed argument is the result, as for other calls: (count (map f 5)) is the error of map, not an error of count.

DUST
(errors/message (count (lists/keep (fn [x] x) 0)))
(errors/message (count (map (fn [x] x) 5)))
(errors/message (count (lists/filter (fn [x] x) true)))
=
DUST Result
"expected a list or null"
"expected a list or null"
"expected a list or null"

3.5.1.6. empty?

Function

(empty? collection) → boolean

Returns whether count is zero. Lists, pointers, maps, strings, bytes, and null are accepted.

DUST
(empty? [])
(empty? {})
(empty? null)
(empty? "x")
=
DUST Result
true
true
true
false
DUST
(errors/message (empty? (lists/keep (fn [x] x) 0)))
(errors/message (empty? (map (fn [x] x) 5)))
(errors/message (empty? (lists/filter (fn [x] x) 1.5)))
=
DUST Result
"expected a list or null"
"expected a list or null"
"expected a list or null"

3.5.1.7. first

Function

(first list) → value

Returns the first element or pointer segment, or null when empty.

DUST
(first ["a" "b"])
(first [])
(first [false null])
=
DUST Result
"a"
null
false

3.5.1.8. rest

Function

(rest list) → list

Returns a fresh sequence without the first element. A pointer produces a pointer; an empty list produces [] and an empty pointer produces the root pointer.

DUST
(rest ["a" "b" "c"])
(rest ["a"])
(rest [])
(rest null)
(rest ["a" null false])
(rest ["a" ["b" "c"] {name "Ada"}])
(let [list ["a" "b" "c"]] [(rest list) list])
=
DUST Result
[["b" "c"] [] [] [] [null false] [["b" "c"] {name "Ada"}] [["b" "c"] ["a" "b" "c"]]]
DUST
{boolean (rest false)
 extra (rest ["a" "b"] 1)
 map (rest {a 1 b 2})
 missing (rest)
 number (rest 2)
 string (rest "abc")}
→
Evaluation cases
#cases [{output #err <mismatch type>
         select "string"}
        {output #err <mismatch type>
         select "map"}
        {output #err <mismatch type>
         select "number"}
        {output #err <mismatch type>
         select "boolean"}
        {output #err <arity mismatch>
         select "missing"}
        {output #err <arity mismatch>
         select "extra"}]

3.5.1.9. jsonptr

Function

(jsonptr text) → pointer

Converts RFC 6901 text to a pointer. The empty string gives the root pointer; a nonempty string must start with / and contain only valid ~0 and ~1 escapes. Invalid text gives #err <invalid value>; a non-string gives #err <mismatch type>.

3.5.1.10. get

Function

(get root path) → value
(get root path default) → value

Returns the value selected by path in root, or default if an entry is missing. Without default, a missing entry returns null. A selected value of null or false is returned unchanged, not replaced by default. get does not modify root or copy the selected value. A map or list in callee position calls get with itself as root: see Calling a map or list. In a packed math value, an index selects a part and a string swizzles a vector: see Destructuring and lookup.

A missing key or out-of-range nonnegative list index returns the default, including during nested traversal. An empty path returns root.

DUST
(get {name "Ada"} "name")
(get {settings {theme "dark"}} (jsonptr "/settings/theme"))
(get {users [{name "Ada"} {name "Bea"}]} ["users" 1 "name"])
(get {} "theme" "default")
=
DUST Result
"Ada"
"dark"
"Bea"
"default"

An integer index into a Bytes value selects the byte there, an integer from 0 to 255.

DUST
(get #b64 "F8gHWw==" 0)
(get #b64 "F8gHWw==" 3)
(get #b64 "F8gHWw==" 4)
(get #b64 "F8gHWw==" 4 "none")
(get #b64 "AP8=" 1)
(get #b64 "F8gHWw==" [1])
(contains? #b64 "F8gHWw==" 3)
(contains? #b64 "F8gHWw==" 4)
(first #b64 "F8gHWw==")
(first #b64 "")
(lists/last #b64 "F8gHWw==")
(lists/nth #b64 "F8gHWw==" 1)
(get #b64 "F8gHWw==" "a")
(get #b64 "F8gHWw==" -5)
=
DUST Result
23
91
null
"none"
255
200
true
false
23
null
91
200
#err {<mismatch type>
      message "lists require integer indices"}
null

3.5.1.11. put

Function

(put root path value) → collection

Stores value at path in root in place and returns the same root collection. Inserts or replaces a map entry, or replaces an existing list element. A list index equal to its length appends one element. Larger indices are errors. Values replace rather than merge, and null is stored rather than deleted. Creates maps, never lists, for missing or null intermediate values. Integer path segments require an existing list.

The root must be a map or list, not null. An empty path is an error. Path, type, and bounds errors leave the target unchanged. value is stored without copying, so a collection reachable from more than one place shows the change in each. Use collections/copy to change a copy instead.

DUST
(let [user {name "Ada"}] [(put user "name" "Bea") user])
(put {settings {theme "light"}} (jsonptr "/settings/theme") "dark")
(put {users [{name "Ada"}]} ["users" 0 "name"] "Bea")
=
DUST Result
[[{name "Bea"} {name "Bea"}] {settings {theme "dark"}} {users [{name "Bea"}]}]
DUST
(let [user {name "Ada"} changed (put (collections/copy user) "name" "Bea")] [user changed])
(let [root {settings {theme "light"}} changed (put (collections/copy root) (jsonptr "/settings/theme") "dark")] [root changed])
(let [root {users [{name "Ada"}]} changed (put (collections/copy root "shallow") ["users" 0 "name"] "Bea")] [root changed])
(let [root {users [{name "Ada"}]} changed (put (collections/copy root "shallow") "users" [])] [root changed])
→
Canonical DUST
(let [user {name "Ada"} changed (put (collections/copy user) "name" "Bea")] [user changed])
(let
  [root {settings {theme "light"}}
   changed (put (collections/copy root) (jsonptr "/settings/theme") "dark")]
  [root changed])
(let
  [root {users [{name "Ada"}]}
   changed (put (collections/copy root "shallow") ["users" 0 "name"] "Bea")]
  [root changed])
(let
  [root {users [{name "Ada"}]} changed (put (collections/copy root "shallow") "users" [])]
  [root changed])
=
DUST Result
[[{name "Ada"} {name "Bea"}] [{settings {theme "light"}} {settings {theme "dark"}}]
 [{users [{name "Bea"}]} {users [{name "Bea"}]}] [{users [{name "Ada"}]} {users []}]]

A change is visible through every value that shares the changed collection:

DUST
(let [original {profile {name "Ada"} settings {theme "dark"}}
      renamed (put (collections/copy original "shallow") "profile" {name "Bea"})]
  (put renamed ["settings" "theme"] "light")
  [original renamed])
→
Canonical DUST
(let
  [original {profile {name "Ada"}
             settings {theme "dark"}}
   renamed (put (collections/copy original "shallow") "profile" {name "Bea"})]
  (put renamed ["settings" "theme"] "light")
  [original renamed])
=
DUST Result
{profile {name "Ada"}
 settings {theme "light"}}
{profile {name "Bea"}
 settings {theme "light"}}

3.5.1.12. remove

Function

(remove root path) → collection

Removes the entry selected by path from root in place and returns the same root collection. Removes a map member or a list element, shifting later list elements left. Empty parent collections are not removed. A missing key, out-of-range nonnegative index, or missing or null intermediate value leaves root unchanged. No containers are created.

The root must be a map or list, not null. An empty path produces #err <invalid value>. Path and type errors leave the target unchanged.

DUST
(let [m {a "b"}] [(remove m "a") m])
(let [m {}] [(remove m "a") m])
(let [m {a {b 1}}] [(remove m (jsonptr "/a/b")) m])
=
DUST Result
[[{} {}] [{} {}] [{a {}} {a {}}]]
DUST
(let [m {a 1 b 2} changed (remove (collections/copy m) "a")] [m changed])
(let [m {a {b 1 c 2}} changed (remove (collections/copy m) (jsonptr "/a/b"))] [m changed])
(let [m {a {b 1 c 2}} changed (remove (collections/copy m "shallow") (jsonptr "/a/b"))] [m changed])
(let [xs ["Ada" "Bea"] changed (remove (collections/copy xs) 0)] [xs changed])
=
DUST Result
[[{a 1 b 2} {b 2}] [{a {b 1 c 2}} {a {c 2}}] [{a {c 2}} {a {c 2}}] [["Ada" "Bea"] ["Bea"]]]

3.5.1.13. contains?

Function

(contains? root path) → boolean

Returns true if path selects a value in root, including null or false, otherwise false.

DUST
(contains? {x null} "x")
(contains?
  {<!x>}
  "x")
(contains? {} "x")
→
Canonical DUST
(contains? {x null} "x")
(contains? <!x> "x")
(contains? {} "x")
=
DUST Result
true
true
false
DUST
(contains? {a null} "a")
(contains? <!a> (jsonptr "/a"))
(contains? {a {b 1}} ["a" "b"])
(contains? ["a" "b"] 1)
(contains? {a 1} "missing")
(contains? {a {}} ["a" "b"])
(contains? ["a" "b"] 2)
(contains? {a/b null} "a/b")
(contains? <!/a> ["/a"])
(contains? <!/a> (jsonptr "/~1a"))
(contains? {users [{name null}]} ["users" 0 "name"])
(contains? {users [{name null}]} (jsonptr "/users/0/name"))
(contains? {"" null} "")
(contains? {} [])
(contains? [] [])
(contains? null "a")
=
DUST Result
true
true
true
true
false
false
false
true
true
true
true
true
true
true
true
false
DUST
{escaped-token (jsonptr "/~2")
 extra (contains? {} "a" false)
 list-key (contains? ["a"] ["0"])
 map-index (contains? {a 1} [0.5])
 missing (contains?)
 missing-path (contains? {})
 path-type (contains? {a 1} true)
 scalar-intermediate (contains? {a 1} ["a" "b"])}
→
Evaluation cases
#cases [{output #err <mismatch type>
         select "path-type"}
        {output #err <invalid value>
         select "escaped-token"}
        {output #err <mismatch type>
         select "map-index"}
        {output #err <mismatch type>
         select "list-key"}
        {output #err <mismatch type>
         select "scalar-intermediate"}
        {output #err <arity mismatch>
         select "missing"}
        {output #err <arity mismatch>
         select "missing-path"}
        {output #err <arity mismatch>
         select "extra"}]

3.5.1.14. keys

Function

(keys map) → list

Returns the map's string keys in ascending Unicode order.

DUST
(keys {a 2 z 1})
(keys {})
(keys null)
=
DUST Result
[["a" "z"] [] []]

3.5.1.15. values

Function

(values map) → list

Returns map values in the same ascending key order used by keys.

DUST
(values {a 2 z 1})
(values {})
(values
  {<!b>
   a null})
=
DUST Result
[[2 1] [] [null false]]

3.5.1.16. pairs

Function

(pairs map) → list

Returns [key value] pairs in the same ascending key order used by keys.

DUST
(pairs {a 2 z 1})
(pairs {})
(pairs {a null})
(pairs null)
(pairs
  {<!"">
   /a 1
   a/b 2})
=
DUST Result
[[["a" 2] ["z" 1]] [] [["a" null]] [] [["" false] ["/a" 1] ["a/b" 2]]]
DUST
{extra (pairs {} {})
 list (pairs ["a" 1])
 missing (pairs)
 string (pairs "abc")}
→
Evaluation cases
#cases [{output #err <mismatch type>
         select "list"}
        {output #err <mismatch type>
         select "string"}
        {output #err <arity mismatch>
         select "missing"}
        {output #err <arity mismatch>
         select "extra"}]

3.5.1.17. from-pairs

Function

(from-pairs list) → map

Returns a fresh map from [key value] pairs in list. Later duplicate keys win.

DUST
(from-pairs [["b" 2] ["a" 1]])
(from-pairs [])
(from-pairs null)
(from-pairs [["a" 1] ["b" 2] ["a" 3]])
(from-pairs [["a" 1] ["a" null] ["b" false]])
(from-pairs [["" 0] ["/a" 1] ["a/b" 2]])
(from-pairs [["nested" {a 1}] ["items" [1 2]]])
(from-pairs
  (pairs
    {<!z>
     a null
     nested {b 2}}))
(pairs (from-pairs [["z" 1] ["a" 2] ["z" 3]]))
=
DUST Result
{a 1
 b 2}
{}
{}
{a 3
 b 2}
{<!b>
 a null}
{"" 0
 /a 1
 a/b 2}
{items [1 2]
 nested {a 1}}
{<!z>
 a null
 nested {b 2}}
[["a" 2] ["z" 3]]
DUST
{empty-pair (from-pairs [[]])
 extra (from-pairs [] [])
 later-invalid-pair (from-pairs [["a" 1] ["b"]])
 list-key (from-pairs [[["a"] 1]])
 long-pair (from-pairs [["a" 1 2]])
 map (from-pairs {a 1})
 map-pair (from-pairs [{a 1}])
 missing (from-pairs)
 non-pair (from-pairs [1])
 null-key (from-pairs [[null "a"]])
 null-pair (from-pairs [null])
 number-key (from-pairs [[1 "a"]])
 short-pair (from-pairs [["a"]])
 string (from-pairs "abc")
 string-pair (from-pairs ["ab"])}
→
Evaluation cases
#cases [{output #err <mismatch type>
         select "map"}
        {output #err <mismatch type>
         select "string"}
        {output #err <mismatch type>
         select "non-pair"}
        {output #err <mismatch type>
         select "map-pair"}
        {output #err <mismatch type>
         select "string-pair"}
        {output #err <invalid value>
         select "empty-pair"}
        {output #err <invalid value>
         select "null-pair"}
        {output #err <invalid value>
         select "short-pair"}
        {output #err <invalid value>
         select "long-pair"}
        {output #err <mismatch type>
         select "number-key"}
        {output #err <mismatch type>
         select "null-key"}
        {output #err <mismatch type>
         select "list-key"}
        {output #err <invalid value>
         select "later-invalid-pair"}
        {output #err <arity mismatch>
         select "missing"}
        {output #err <arity mismatch>
         select "extra"}]

3.5.1.18. pack

Macro

(pack members) → map

Builds a map from locals that have the same names as its keys.

The argument is written as a map. A tag reads the local with the same name as its key, thus (pack <name spice>) is {name name spice spice}. Other members stay as written and are evaluated as in any map. A tag group as a value is a literal map of true members. It does not read locals, and pack supplies that operation.

DUST
(let [name "Chani" spice 80] (pack <name spice>))
(let
  [name "Chani" spice 80 crew ["Stilgar"]]
  (pack
    {<name spice>
     count 1
     first (first crew)}))
(let [name "Chani"] (= (pack <name>) {name name}))
(pack {})
(macroexpand-1
  `(pack
     {<name spice>
      unit "kg"}))
=
DUST Result
{name "Chani"
 spice 80}
{count 1
 first "Stilgar"
 name "Chani"
 spice 80}
true
{}
{name name
 spice spice
 unit "kg"}

A tag is a member whose value is true. Thus {<a> done true} is the same data as <a done>, and pack reads the local done. Write a literal true in an ordinary map. A let, fn or for binding with the name pack shadows the macro, as it does for every macro. A top-level def with that name does not shadow it, as for the other core macros.

DUST
(let [pack (fn [m] (count m))] (pack <a b>))
(let [done 5 a 1] (pack <a done>))
=
DUST Result
2
{a 1
 done 5}

A name with no binding gives that member #err <name unbound>, as a reference does in any map.

DUST
(pack <missing>)
=
DUST Result
{missing #err <name unbound>}

A negated tag, an argument that is not written as a map, and a wrong number of arguments are #err <invalid program>.

DUST
{list (pack [1 2])
 negated (let [name 1] (pack <!name>))
 none (pack)
 two (let [a 1] (pack <a> <a>))}
→
Evaluation cases
#cases [{output #err <invalid program>
         select "negated"}
        {output #err <invalid program>
         select "list"}
        {output #err <invalid program>
         select "none"}
        {output #err <invalid program>
         select "two"}]

3.6. Ordering

These core functions compare values, sort lists, remove duplicates, and group values by key. They are part of the core library; see DUST for source notation, evaluation, and special forms.

3.6.1. Ordering, uniqueness, and grouping

3.6.1.1. compare

Function

(compare first second) → integer

Returns -1, 0, or 1 when first sorts before, ties with, or sorts after second, using sort ordering.

DUST
(compare 2 5)
(compare 5 5)
(compare 5 2)
(compare "a" "b")
(compare "猫" "é")
(compare false true)
(compare true false)
(compare null null)
(compare 1.5 2.5)
(compare -0.0 0.0)
(compare #link 2 #link 1)
(compare 9007199254740992 9007199254740993)
=
DUST Result
-1
0
1
-1
1
-1
1
0
-1
0
1
-1
DUST
{extra-argument (compare 1 2 3)
 functions (compare (fn [x] x) (fn [x] x))
 lists (compare [1] [1])
 maps (compare {a 1} {a 1})
 mixed-numbers (compare 1 1.0)
 mixed-scalars (compare "a" 1)
 no-arguments (compare)
 null-and-value (compare null 1)
 one-argument (compare 1)}
→
Evaluation cases
#cases [{output #err <mismatch type>
         select "mixed-numbers"}
        {output #err <mismatch type>
         select "mixed-scalars"}
        {output #err <mismatch type>
         select "null-and-value"}
        {output #err <mismatch type>
         select "lists"}
        {output #err <mismatch type>
         select "maps"}
        {output #err <mismatch type>
         select "functions"}
        {output #err <arity mismatch>
         select "no-arguments"}
        {output #err <arity mismatch>
         select "one-argument"}
        {output #err <arity mismatch>
         select "extra-argument"}]

3.6.1.2. sort

Function

(sort list) → list
(sort comparator list) → list

Sorts list in place, stably, and returns the same list, without copying its elements. The list's order changes only after all comparisons succeed. list must be a list, not null or a pointer. By default, sorts in ascending order and requires all elements to have the same kind. Orderable kinds are null, boolean, integer, float, string, link, UTC, duration, SHA-256, and pointer. Pointer segments compare lexicographically, with an index before a key; a shorter prefix sorts before its extension. Integers and nominal integer payloads compare exactly. Strings compare by Unicode code point order, booleans put false before true, and SHA-256 values compare their bytes. Null values tie.

Equal values keep their input order. With default ordering, compound values, functions, expression forms, and mixed kinds are errors, including in singleton lists.

A supplied comparator receives two elements and returns a negative integer, zero, or a positive integer when the first sorts before, ties with, or sorts after the second. Custom comparators can order any element kinds. A non-function comparator produces #err <expected function>. A non-integer result produces #err <mismatch type>. Comparator errors stop sorting and are returned. The comparator must define a consistent order and must not change the input list or the values being compared. Its call order and call count are not guaranteed.

DUST
(sort [3 1 2])
(sort ["猫" "é" "a"])
(sort [false true false])
(sort [#link 2 #link 1])
(sort [null null])
=
DUST Result
[[1 2 3] ["a" "é" "猫"] [false false true] [#link 1 #link 2] [null null]]
DUST
(let [xs [3 1 2]] [(sort xs) xs])
(let [xs []] [(sort xs) xs])
(let [xs [2 1 2]] [(sort xs) xs])
=
DUST Result
[[[1 2 3] [1 2 3]] [[] []] [[1 2 2] [1 2 2]]]
DUST
(sort [1 1.0])
=
DUST Result
#err <mismatch type>
DUST
(sort [[1]])
=
DUST Result
#err <mismatch type>
DUST
(sort (fn [a b] (- b a)) [1 3 2])
(sort (fn [a b] (- (get a "rank") (get b "rank"))) [{id "a" rank 2} {id "b" rank 1} {id "c" rank 2}])
→
Canonical DUST
(sort (fn [a b] (- b a)) [1 3 2])
(sort
  (fn [a b] (- (get a "rank") (get b "rank")))
  [{id "a" rank 2} {id "b" rank 1} {id "c" rank 2}])
=
DUST Result
[[3 2 1] [{id "b" rank 1} {id "a" rank 2} {id "c" rank 2}]]

3.6.1.3. distinct

Function

(distinct list) → list

Returns a fresh list retaining the first occurrence of each distinct typed value. Collections compare structurally, with map member order ignored. Kinds remain distinct: integer 1 and float 1.0 are separate values. Functions compare by identity. Positive and negative floating zero compare equal.

DUST
(distinct [1 1.0 1 1.0])
(distinct [{a 1 b 2} {a 1 b 2} ["a"] ["a"]])
(distinct [null false null false])
(let [f (fn [] 1) g (fn [] 1)] (count (distinct [f f g])))
=
DUST Result
[[1 1.0] [{a 1 b 2} ["a"]] [null false] 2]

3.6.2. Ordered comparisons

The ordered comparisons accept the same scalar kinds as sort and require matching kinds. They require at least two arguments and validate every argument's kind before comparing adjacent pairs from left to right. As ordinary functions, all argument expressions evaluate before comparison begins.

3.6.2.1. <

Function

(< first second more*) → boolean

Returns whether the arguments are strictly increasing.

DUST
(< 1 2 3)
(< 1 1)
(< "a" "é" "猫")
(< false true)
=
DUST Result
true
false
true
true
DUST
(< 1 1.0)
=
DUST Result
#err <mismatch type>
DUST
(< 2 1 "x")
=
DUST Result
#err <mismatch type>
DUST
(< [1] [2])
=
DUST Result
#err <mismatch type>
DUST
(< 1)
=
DUST Result
#err <arity mismatch>

3.6.2.2. <=

Function

(<= first second more*) → boolean

Returns whether the arguments are nondecreasing.

DUST
(<= 1 1 2)
(<= 2 1 0)
(<= null null)
=
DUST Result
true
false
true

3.6.2.3. >

Function

(> first second more*) → boolean

Returns whether the arguments are strictly decreasing.

DUST
(> 3 2 1)
(> 1 1)
(> #link 2 #link 1)
=
DUST Result
true
false
true

3.6.2.4. >=

Function

(>= first second more*) → boolean

Returns whether the arguments are nonincreasing.

DUST
(>= 3 3 2)
(>= 1 2)
(>= true false)
=
DUST Result
true
false
true

3.7. Types

These core functions test and convert values. They are part of the core library; see DUST for source notation, evaluation, and special forms.

3.7.1. Type Predicates

For structural validation, named definitions and generated checking, see Schemas and contracts.

3.7.1.1. error?

Function

(error? value) → boolean

Returns true if value is an error and false otherwise. error? receives an error argument; a call of most other functions returns it (see Evaluation).

DUST
[(error? #err "app/oh-no") (error? (/ 1 0)) (error? (= 1 1.0)) (error? (=))
 (let [inspect :error?] (inspect (/ 1 0))) (error? null) (error? false) (error? true) (error? 0)
 (error? 1.0) (error? "") (error? "dust/type-mismatch") (error? "#err dust/type-mismatch")
 (error? []) (error? {}) (error? {error "dust/type-mismatch"}) (error? (fn [] null))
 (error? `name)]
→
Canonical DUST
(error? #err "app/oh-no")
(error? (/ 1 0))
(error? (= 1 1.0))
(error? (=))
(let [inspect :error?] (inspect (/ 1 0)))
(error? null)
(error? false)
(error? true)
(error? 0)
(error? 1.0)
(error? "")
(error? "dust/type-mismatch")
(error? "#err dust/type-mismatch")
(error? [])
(error? {})
(error? {error "dust/type-mismatch"})
(error? (fn [] null))
(error? `name)
=
DUST Result
true
true
true
true
true
false
false
false
false
false
false
false
false
false
false
false
false
false
DUST
(error?)
=
DUST Result
#err <arity mismatch>
DUST
(error? 1 2)
=
DUST Result
#err <arity mismatch>

3.7.1.2. null?

Function

(null? x) → boolean

Returns true if x is null, otherwise false.

DUST
[(null? null)
 (null? "nil")
 (null? "null")
 (null? false)]
→
Canonical DUST
(null? null)
(null? "nil")
(null? "null")
(null? false)
=
DUST Result
true
false
false
false

3.7.1.3. string?

Function

(string? s) → boolean

Returns true if s is a string, otherwise false.

DUST
[(string? "nil")
 (string? "")
 (string? "42")
 (string? null)
 (string? 42)]
→
Canonical DUST
(string? "nil")
(string? "")
(string? "42")
(string? null)
(string? 42)
=
DUST Result
true
true
true
false
false

3.7.1.4. bitset?

Function

(bitset? value) → boolean

Returns true for a Bitset, otherwise false.

DUST
(bitset? #bitset [])
(bitset? [1])
(bitset? #b64 "")
=
DUST Result
true
false
false

3.7.1.5. bytes?

Function

(bytes? value) → boolean

Returns true if value is a Bytes value, otherwise false.

DUST
(bytes? #b64 "aGk=")
(bytes? #b64 "")
(bytes? (bytes/concat))
(bytes? "aGk=")
(bytes? [104 105])
(bytes? null)
(bytes? #hash #xxh3-64 "78af5f94892f3950")
(string? #b64 "aGk=")
(list? #b64 "aGk=")
=
DUST Result
true
true
true
false
false
false
false
false
false

3.7.1.6. int?

Function

(int? n) → boolean

Returns true if n is an integer, otherwise false. A link scalar is not an integer.

DUST
[(int? 0)
 (int? -42)
 (int? 1.0)
 (int? 1e0)
 (int? "42")
 (int? (+ 1 2))]
→
Canonical DUST
(int? 0)
(int? -42)
(int? 1.0)
(int? 1.0)
(int? "42")
(int? (+ 1 2))
=
DUST Result
true
true
false
false
false
true

3.7.1.7. float?

Function

(float? n) → boolean

Returns true if n is a floating-point number, otherwise false.

DUST
[(float? 1.0)
 (float? 1e0)
 (float? 1)
 (float? "1.0")]
→
Canonical DUST
(float? 1.0)
(float? 1.0)
(float? 1)
(float? "1.0")
=
DUST Result
true
true
false
false

3.7.1.8. number?

Function

(number? n) → boolean

Returns true if n is an integer or a float, otherwise false. A link scalar is not a number.

DUST
[(number? 1)
 (number? 1.5)
 (number? "1")
 (number? true)
 (number? null)]
→
Canonical DUST
(number? 1)
(number? 1.5)
(number? "1")
(number? true)
(number? null)
=
DUST Result
true
true
false
false
false

3.7.1.9. jsonptr?

Function

(jsonptr? value) → boolean

Returns true for a pointer and false for other values. A pointer is not a list, even though the list functions accept it.

(jsonptr? /a)   ; true
(jsonptr? "/a") ; false

3.7.1.10. list?

Function

(list? xs) → boolean

Returns true if xs is a list, otherwise false.

DUST
[(list? [])
 (list? [1])
 (list? {})
 (list? null)]
→
Canonical DUST
(list? [])
(list? [1])
(list? {})
(list? null)
=
DUST Result
true
true
false
false

3.7.1.11. map?

Function

(map? m) → boolean

Returns true if m is a map, otherwise false.

DUST
[(map? {})
 (map? {name "Ada"})
 (map? [])
 (map? null)]
→
Canonical DUST
(map? {})
(map? {name "Ada"})
(map? [])
(map? null)
=
DUST Result
true
true
false
false

3.7.1.12. boolean?

Function

(boolean? b) → boolean

Returns true if b is either true or false, otherwise false.

DUST
[(boolean? true)
 (boolean? false)
 (boolean? null)
 (boolean? "true")
 (boolean? 0)]
→
Canonical DUST
(boolean? true)
(boolean? false)
(boolean? null)
(boolean? "true")
(boolean? 0)
=
DUST Result
true
true
false
false
false

3.7.1.13. template?

Function

(template? value) → boolean

Returns true if value is a string template, otherwise false.

DUST
(let [t (templates/from-parts {strings ["hello-" ""] values ["Ada"]})]
 [(template? t)
  (string? t)
  (template? "hello-Ada")
  (templates/parts t)
  (str t)
  (strings/starts-with? t "hello")
  (= t "hello-Ada")
  (count t)
  (strings/join [t "!"] "")
  (compare t "hello-Ada")
  (get {hello-Ada 42} t)])
(templates/render (templates/from-parts {strings ["hello-" ""] values ["<Ada>"]}) {escape (strings/escape "html-text")})
(let [name "Ada"] #template [["hello-" ""] [name]])
#template [["outer-" ""] [#template [["inner-" ""] ["Ada"]]]]
→
Canonical DUST
(let
  [t (templates/from-parts {strings ["hello-" ""] values ["Ada"]})]
  [(template? t) (string? t) (template? "hello-Ada") (templates/parts t)
   (str t) (strings/starts-with? t "hello") (= t "hello-Ada") (count t)
   (strings/join [t "!"] "") (compare t "hello-Ada") (get {hello-Ada 42} t)])
(templates/render
  (templates/from-parts {strings ["hello-" ""] values ["<Ada>"]})
  {escape (strings/escape "html-text")})
(let [name "Ada"] ~"hello-,name")
#template [["outer-" ""] [#template [["inner-" ""] ["Ada"]]]]
=
DUST Result
[[true true false {strings ["hello-" ""] values ["Ada"]} "hello-Ada" true true 9 "hello-Ada!" 0 42]
 "hello-&lt;Ada&gt;" "hello-Ada"
 "outer-inner-Ada"]

3.7.1.14. fn?

Function

(fn? f) → boolean

Returns true if f is a function, otherwise false.

DUST
[(fn? (fn [] null))
 (fn? :+)
 (fn? "+")
 (fn? [])]
→
Canonical DUST
(fn? (fn [] null))
(fn? :+)
(fn? "+")
(fn? [])
=
DUST Result
true
true
false
false

3.7.1.15. local?

Function

(local? v) → boolean

Returns true if v is a local reference, such as the quoted form `name, otherwise false.

DUST
[(local? `name)
 (local? `:name)
 (local? ".name")
 (local? "name")]
→
Canonical DUST
(local? `name)
(local? `:name)
(local? ".name")
(local? "name")
=
DUST Result
true
false
false
false

3.7.1.16. const?

Function

(const? v) → boolean

Returns true if v is a constant reference, such as the quoted form `:name, otherwise false. A local and a constant with the same name are not equal.

DUST
[(const? `:math/pi)
 (const? `math/pi)
 (const? :math/pi)
 (const? ":math/pi")]
→
Canonical DUST
(const? `:math/pi)
(const? `math/pi)
(const? :math/pi)
(const? ":math/pi")
=
DUST Result
true
false
false
false

3.7.1.17. uuid?

Function

(uuid? value) → boolean

Returns true for a UUID, otherwise false. A string that spells a UUID is not one.

DUST
(uuid? #uuid "00000000-0000-4000-8000-00000000000c")
(uuid? "00000000-0000-4000-8000-00000000000c")
(uuid? #b64 "")
=
DUST Result
true
false
false

3.7.1.18. utc?

Function

(utc? value) → boolean

Returns true for a UTC timestamp, otherwise false. It is the kind predicate that time/utc? also provides.

DUST
(utc? #utc "2026-01-01T00:00:00Z")
(utc? #dur "PT10S")
(utc? 1767225600)
=
DUST Result
true
false
false

3.7.1.19. duration?

Function

(duration? value) → boolean

Returns true for a duration, otherwise false. It is the kind predicate that time/duration? also provides.

DUST
(duration? #dur "PT10S")
(duration? #utc "2026-01-01T00:00:00Z")
(duration? 10)
=
DUST Result
true
false
false

3.7.1.21. hash?

Function

(hash? value) → boolean

Returns true for a #hash digest, otherwise false.

DUST
(hash? (hashes/digest "sha256" "x"))
(hash? "x")
(hash? #b64 "")
=
DUST Result
true
false
false

3.7.1.22. regex?

Function

(regex? value) → boolean

Returns true for a regular expression, otherwise false. A compiled matcher is not a regular expression; see regex-matcher?.

DUST
(regex? #re "a+")
(regex? (regexes/matcher #re "a+" "aaa"))
(regex? "a+")
=
DUST Result
true
false
false

3.7.1.23. regex-matcher?

Function

(regex-matcher? value) → boolean

Returns true for a compiled regular expression matcher, otherwise false.

DUST
(regex-matcher? (regexes/matcher #re "a+" "aaa"))
(regex-matcher? #re "a+")
(regex-matcher? "aaa")
=
DUST Result
true
false
false

3.7.1.24. peg?

Function

(peg? value) → boolean

Returns true for a compiled PEG, otherwise false.

DUST
(peg? (pegs/compile "a"))
(peg? "a")
(peg? #re "a")
=
DUST Result
true
false
false

3.7.1.25. invoke?

Function

(invoke? value) → boolean

Returns true for an invocation form, such as `(f 1), otherwise false.

DUST
(invoke? `(f 1))
(invoke? `f)
(invoke? [f 1])
=
DUST Result
true
false
false

3.7.1.26. quote?

Function

(quote? value) → boolean

Returns true for a quote form, such as the value of ``x, otherwise false.

DUST
(quote? ``x)
(quote? `x)
(quote? `~x)
=
DUST Result
true
false
false

3.7.1.27. quasiquote?

Function

(quasiquote? value) → boolean

Returns true for a quasiquote form, such as the value of `~x, otherwise false.

DUST
(quasiquote? `~x)
(quasiquote? ``x)
(quasiquote? `(f x))
=
DUST Result
true
false
false

3.7.1.28. unquote?

Function

(unquote? value) → boolean

Returns true for an unquote form, such as the value of `,x, otherwise false.

DUST
(unquote? `,x)
(unquote? `,@x)
(unquote? `x)
=
DUST Result
true
false
false

3.7.1.29. unquote-splicing?

Function

(unquote-splicing? value) → boolean

Returns true for an unquote-splicing form, such as the value of `,@x, otherwise false.

DUST
(unquote-splicing? `,@x)
(unquote-splicing? `,x)
(unquote-splicing? [x])
=
DUST Result
true
false
false

3.7.1.30. tagged?

Function

(tagged? value) → boolean

Returns true for a tagged value, otherwise false. An error is not tagged data: error? tests for one.

DUST
(tagged? #point [1 2])
(tagged? {point [1 2]})
(tagged? 1)
=
DUST Result
true
false
false

3.7.2. Type Conversion

3.7.2.1. int

Function

(int value) → integer

Returns an integer unchanged, truncates a float toward zero, or parses a signed decimal string exactly. String input accepts an optional ASCII sign followed by ASCII decimal digits, including leading zeros. Whitespace, decimal points, exponents, and hexadecimal notation are rejected. Values outside signed 64-bit range are errors. Booleans, null, and nominal types such as links are rejected.

DUST
(int "9007199254740993")
(int -1.9)
(int "+00042")
(int "-9223372036854775808")
=
DUST Result
9007199254740993
-1
42
-9223372036854775808
DUST
(int "9223372036854775808")
=
DUST Result
#err <integer overflow>
DUST
(int "1.5")
=
DUST Result
#err <invalid value>
DUST
(int #link 1)
=
DUST Result
#err <mismatch type>

3.7.2.2. float

Function

(float value) → float

Converts an integer to a float, returns a float unchanged, or parses a signed decimal string with an optional decimal point and exponent. Integer conversion can lose precision; for example, integer 9007199254740993 converts to 9007199254740992.0. Whitespace, hexadecimal notation, NaN, and infinity are rejected. Overflow is an error; underflow to zero is permitted. Booleans, null, and nominal types such as links are rejected.

DUST
(float 3)
(float "+.5")
(float "1.e+2")
(float "1e-999")
=
DUST Result
3.0
0.5
100.0
0.0
DUST
(float "1e999")
=
DUST Result
#err <float overflow>
DUST
(float " 1")
=
DUST Result
#err <invalid value>
DUST
(float #link 1)
=
DUST Result
#err <mismatch type>

3.7.2.3. str

Function

(str values*) → string

Converts zero or more values to strings and concatenates them in argument order. It inserts no spaces or other separators. With no arguments, returns the empty string.

Strings contribute their contents without added quotes or escaping. A null argument contributes the empty string. Numbers and booleans use their RON representations. Lists, maps, and representable tagged values use canonical RON formatting. RON has one canonical format; layout follows its normal formatting rules. The formatter appends no terminal newline, and str uses those canonical bytes unchanged. Line breaks in formatted collections are retained.

Collections are printed as complete values, not flattened into arguments. Within collections, null is printed as null and strings are quoted when required to preserve their values.

str is an ordinary function. Its arguments are evaluated before conversion. String contents are text and are not interpreted as expressions.

(str)                     ; => ""
(str "a" null "b")            ; => "ab"
(str "order-" 42 ".json")      ; => "order-42.json"
DUST
(do [
  (str [null "null" 1 true])
  (str {z 2 a 1})
  (str `name)
  (str #utc "2026-10-24T12:34:56Z")
])
→
Canonical DUST
(do [(str [null "null" 1 true]) (str {a 1 z 2}) (str `name) (str #utc "2026-10-24T12:34:56Z")])
=
DUST Result
""[null "null" 1 true]""
"""
  a 1
  z 2
"""
"#local name"
"#utc 2026-10-24T12:34:56Z"

3.7.2.4. boolean

Function

(boolean value) → boolean

Returns false if value is null or false, otherwise true.

DUST
(boolean "")
=
DUST
(boolean 0)
=
DUST
(boolean {})
=
DUST
(boolean [])
=

3.7.2.5. format

Function

(format template args*) → string

Returns a string by substituting args into the conversion specifications in template.

The syntax is printf-style. DUST supports %v for value conversion and requires the argument types below.

A conversion has the form %[flags][width][.precision]conversion. Each conversion consumes one argument in order, except %%, which consumes none. Other text is copied unchanged. The string template contains no embedded expressions.

Conversion Argument Result
s String String contents
v Any value Text produced by str
d, i Integer Signed decimal
o Integer Unsigned octal
x, X Integer Unsigned hexadecimal, lowercase or uppercase
f Float Fixed-point decimal
e, E Float Scientific notation with e or E
g, G Float Compact decimal or scientific notation
% None A literal percent sign, written %%

Width is a decimal minimum field width. Padding uses spaces on the left by default and never truncates a value. Width counts UTF-8 bytes, not code points or display columns.

Flag Applies to Effect
- All except % Left-align within the field
+ Signed decimal and floats Always include a sign
Space Signed decimal and floats Prefix nonnegative values with a space
0 Numeric conversions Pad with zeros after any sign or base prefix
# o, x, X Alternate form with an octal or hexadecimal prefix
# Floats Keep the decimal point, and keep trailing zeros for g and G

The + flag overrides the space flag, and - overrides 0. Integer precision also overrides 0. Flags not applicable to a conversion are errors.

Precision is a decimal count after ., with an omitted count meaning zero. For integers it sets the minimum digit count. For f, e, and E it sets the fractional digit count, defaulting to six. For g and G it sets the significant digit count, defaulting to six, with zero treated as one. These numeric conversions follow C printf formatting rules, including rounding and alternate forms. Precision is not supported for s or v. The %% escape accepts no flags, width, or precision.

Integer formatting preserves all 64 bits without conversion through a float. Octal and hexadecimal conversions interpret negative integers modulo 2^64. Floating-point formatting rounds the stored binary value, not an exact decimal value. Numeric output uses . as the decimal point and no locale-specific grouping. There is no implicit numeric conversion: %.2f requires a float, so integer 42 is an error. The s conversion requires a string, while v accepts any value, including null as the empty string.

Dynamic width or precision (*), positional arguments ($), length modifiers, and conversions not listed above are unsupported. Invalid specifications produce #err <invalid value>. An incompatible argument type, including a non-string template, produces #err <mismatch type>. Missing or extra arguments produce #err <arity mismatch>. Formatting, field widths, and precision are subject to the execution and output resource limits.

DUST
(format "Hello, %s!" "Ada")
(format "Invoice %04d: %.2f EUR" 7 12.5)
(format "Progress: %d%%" 75)
(format "Result: %v" {count 3})
=
DUST Result
"Hello, Ada!"
"Invoice 0007: 12.50 EUR"
"Progress: 75%"
"Result: {count 3}"

3.8. Arithmetic

These core functions provide arithmetic. They are part of the core library; see DUST for source notation, evaluation, and special forms.

3.8.1. Arithmetic

Arithmetic proceeds from left to right. Links are not numbers and are rejected by numeric operations. Numbers never convert implicitly: the numeric operands of one call must be all integers or all floats, and an integer paired with a float is a type mismatch. Convert explicitly with float or int. Integer overflow and non-finite floating-point results are errors.

The shared operators also support the explicit temporal combinations below. UTC and duration values retain their nominal types and signed 100 ns tick precision. A number never becomes an implicit duration.

Operation Result
UTC + duration; duration + UTC UTC
Duration + duration Duration
UTC - duration UTC
UTC - UTC; duration - duration Duration
Duration * integer; integer * duration Duration
Duration / integer Duration, truncated toward zero
Duration / duration Float ratio

Other temporal combinations are type errors. See the Time library for temporal examples and bounds.

3.8.1.1. +

Function

(+) → integer
(+ value) → value
(+ value other more*) → value

Returns the sum of its arguments.

With no arguments, returns 0. With one argument, returns that numeric or temporal value unchanged.

DUST
[(+) (+ 7) (+ 1 2 3)
 (+ 1.0) (+ 1.0 2.5) (+ -2 2)]
→
Canonical DUST
(+)
(+ 7)
(+ 1 2 3)
(+ 1.0)
(+ 1.0 2.5)
(+ -2 2)
=
DUST Result
0
7
6
1.0
3.5
0
DUST
(+ 9223372036854775807 1)
=
DUST Result
#err <integer overflow>
DUST
(+ 1e+308 1e+308)
=
DUST Result
#err <float overflow>
DUST
(+ 1 "2")
=
DUST Result
#err <mismatch type>
DUST
(+ 1 2.5)
=
DUST Result
#err <mismatch type>

3.8.1.2. -

Function

(- value more*) → value

With one argument, returns its negation. With additional arguments, subtracts each from the running result in order. At least one argument is required. Numeric operands follow the arithmetic rules above; temporal operands use the combinations in the table. Integer overflow and non-finite floating-point results are errors, including when negating the minimum integer. Unary subtraction also negates durations; UTC timestamps cannot be negated.

DUST
(- 3)
(- 10 3 2)
(- 10.0 2.5)
(- -9007199254740993)
(- 9007199254740995 1 1)
(- 0)
=
DUST Result
-3
5
7.5
9007199254740993
9007199254740993
0
DUST
(-)
=
DUST Result
#err <argument missing>
DUST
(- -9223372036854775808)
=
DUST Result
#err <integer overflow>
DUST
(- -9223372036854775808 1)
=
DUST Result
#err <integer overflow>
DUST
(- 10 2.5)
=
DUST Result
#err <mismatch type>
DUST
(- -1e+308 1e+308)
=
DUST Result
#err <float overflow>
DUST
(- 1 "x")
=
DUST Result
#err <mismatch type>
DUST
(- #link 1)
=
DUST Result
#err <mismatch type>

3.8.1.3. *

Function

(*) → integer
(* value) → value
(* value other more*) → value

Returns the product of its arguments.

With no arguments, returns 1. With one argument, returns that number or duration unchanged.

DUST
[(*) (* 7) (* 2 3 4)
 (* 1.0) (* 2.0 1.5) (* -2 0)]
→
Canonical DUST
(*)
(* 7)
(* 2 3 4)
(* 1.0)
(* 2.0 1.5)
(* -2 0)
=
DUST Result
1
7
24
1.0
3.0
0
DUST
(* 9223372036854775807 2)
=
DUST Result
#err <integer overflow>
DUST
(* 1e+308 2.0)
=
DUST Result
#err <float overflow>
DUST
(* null)
=
DUST Result
#err <mismatch type>
DUST
(* 2 1.5)
=
DUST Result
#err <mismatch type>

3.8.1.4. /

Function

(/ n) → float
(/ value divisor more*) → value

Returns n divided by d and each additional divisor in more, or the reciprocal of n when called with one argument.

Numeric operands must be all integers or all floats. Numeric division proceeds from left to right and always returns a float, even for integer operands. Duration division follows the temporal combinations in the table above. A zero divisor is an error. A duration requires a divisor; unary duration reciprocals are not defined.

DUST
[(/ 2) (/ 6 3) (/ 1 2) (/ 24 2 3) (/ -2)
 (/ 1 3) (/ 1.0 2.0) (/ 0 2)]
→
Canonical DUST
(/ 2)
(/ 6 3)
(/ 1 2)
(/ 24 2 3)
(/ -2)
(/ 1 3)
(/ 1.0 2.0)
(/ 0 2)
=
DUST Result
0.5
2.0
0.5
4.0
-0.5
0.3333333333333333
0.5
0.0
DUST
(/ 1.0 2)
=
DUST Result
#err <mismatch type>
DUST
(/)
=
DUST Result
#err <argument missing>
DUST
(/ 1 0)
=
DUST Result
#err <division integer zero>
DUST
(/ 0.0)
=
DUST Result
#err <division float zero>
DUST
(/ 1e+308 0.5)
=
DUST Result
#err <float overflow>
DUST
(/ 1 "2")
=
DUST Result
#err <mismatch type>

3.8.1.5. rem

Function

(rem dividend divisor) → number

Returns the remainder with the sign of the dividend. Two integers produce an exact integer remainder; otherwise the result is a float. A zero divisor is an error. The minimum integer divided by -1 has remainder zero.

DUST
(rem -7 3)
(rem 7 -3)
(rem 1.25 0.5)
(rem -9223372036854775808 -1)
=
DUST Result
-1
1
0.25
0
DUST
(rem 1 0)
=
DUST Result
#err <division integer zero>