Skip to the content
Diaspar

Decision D013 · accepted

Core value semantics: equality, numbers, strings, sequences, the REPL

A record of the language's design, as it stood on 2026-11-18: written for the people who build Diaspar, and kept as it was written. Its code is a sketch, not a program of the site, and an older record may show syntax that a later one changed. It names files of the language's source, which is not public yet.

Status: accepted (2026-11-15)

1. Equality: one =

There is one equality operator. Its principle: = compares values, not their representation, and never converts between different kinds.

;; numbers are one kind, compared by mathematical value, exactly
(= 1 1.0)                                ; → true
(= 0.0 -0.0)                             ; → true
(= 9007199254740993 9007199254740992.0)  ; → false: no rounding

;; sequences are one kind, compared element by element
(= '(1 2) #[1 2])                        ; → true
(= (rest #[1 2 3]) #[2 3])               ; → true

;; different kinds are never equal; nothing is converted
(= "1" 1)                                ; → false
(= #[1 2] #{0 1 1 2})                    ; → false: a sequence and a map
(= (Point x: 1 y: 2) #{:x 1 :y 2})       ; → false: a record is its own kind (D010)

The kinds are: numbers, sequences (lists and vectors), maps, sets, strings, keywords, symbols, and each record type. Numbers are integers, floats and decimals (D038: (= 1dec 1) and (= 1.5dec 1.5) are true, (= 0.1dec 0.1) false); a BigInt (std.math.bigint) is a kind of its own.

Replaced (2026-11-18) by D043, accepted and not implemented yet: a BigInt is a number too, a type of the core with the literal 12big, and = and the total order compare integers, floats, decimals and BigInts by exact value, so (= 5big 5) is true. An integer still does not grow into a BigInt: the overflow of §2 stays an error.

  • Equal values hash equally, so 1 and 1.0 are the same map key, and so are '(1 2) and #[1 2].
  • = is reflexive: NaN equals itself, so a NaN inside a vector or a map key does not break equality or lookup. < and > follow IEEE: any comparison with NaN is false.
  • Approximate comparison of floats is a different operation with a different meaning, not a second equality: close? in the std.math module. The compiler may warn when = compares two computed floats.

Why one operator: JavaScript's trouble is not having two operators but converting between kinds ("1" == 1). Python has one == built on the same principle and it works. Clojure's = plus == for numbers is the second operator this avoids. In compiled code, comparing an integer with a float is one run-time check, and where inference knows both sides are integers the compiler emits a direct comparison.

2. Numbers and division

  • / is IEEE floating-point division for any arguments: (/ 7 2) → 3.5, (/ 1 0) → infinity, (/ 0 0) → NaN.
  • Integer division is quot (truncating), with rem and mod. Dividing an integer by zero with them is an error: integers have no infinity.
  • Integer arithmetic that overflows 64 bits is an error.

Why IEEE rather than an error, as Python does: C, Rust, Go, Java, JavaScript, and Julia follow IEEE, and graphics, games, and numeric code depend on it; an error check in a hot loop costs a branch per operation and blocks vectorization. The compiler may warn about division by a literal zero.

Infinity and NaN are constants in the std.math module, std.math.inf and std.math.nan, with no special syntax; negative infinity is (- std.math.inf). The printer prints these full paths, so printed code reads back anywhere; after (use std.math) code may write math.inf. Clojure's reader literals ##Inf and ##NaN are the alternative.

3. The std.math module

Mathematical functions and constants live in the std.math module (D011), not in the prelude, and are imported like any module (D011):

(use std.math [close?])
(close? (+ 0.1 0.2) 0.3)        ; → true
(math.close? a b tolerance: 1e-6)

4. Strings are sequences of graphemes

Following Swift and Ferron (its D19 and D77):

(count "héllo")        ; → 5 graphemes
(count "👨‍👩‍👧")           ; → 1, though it is 5 code points and 18 bytes
(byte-count "👨‍👩‍👧")      ; → 18, O(1)
(map upper "héllo")    ; iteration goes by graphemes
(first "👍🏽 ok")        ; → "👍🏽": a grapheme is a one-grapheme string
(code-points "é")      ; an explicit view of code points
(bytes "é")            ; and of bytes
(nth "hello" 2)        ; error: strings have no index access
  • Storage is UTF-8.
  • count, iteration, and slicing count extended grapheme clusters (UAX #29). count is O(n); byte-count is O(1).
  • There is no separate character type: a grapheme is a string of one grapheme.
  • nth by number is not allowed on strings: reaching grapheme i walks from the start, so a loop over (nth s i) would be quadratic. Iteration, slicing, and subs are the tools.
  • Equality, ordering, and hashing compare bytes, as in Ferron, Python, and Rust. Canonical equivalence goes through explicit normalization: (= (nfc a) (nfc b)).

5. Sequences

  • rest always returns a collection, never nil; an empty rest is (). There is no next. Emptiness is tested with empty?.
  • An empty rest parameter (& more) is (), not nil.
  • first of an empty collection is nil, as get is for a missing key.
  • Sequence functions return lists. conj adds to the front of a list and the end of a vector.

Why no nil from rest: with inferred types (D007) the type of rest stays "list" instead of "list or nil", so chains do not fill up with nil checks, and Clojure's rest/next pair, a standing source of confusion, is not needed.

6. nil is the only absence

  • There is one nil, with no second "nothing" such as JavaScript's undefined, and no Option wrapper.
  • Inference tracks T | nil (D007) and warns when nil is not handled, as Kotlin, TypeScript, and Swift do; the nil pattern makes handling explicit (D015).
  • Whether a map has a key is asked with contains? or a map pattern, which matches only when the key is present; no sentinel value is needed.
(match (get users id)
  nil  (error (UserNotFound id))
  u    (greet u))

Why no Option: JavaScript's and Python's trouble is not nil but the lack of checking, and in JavaScript two kinds of nothing. Kotlin, TypeScript, and Swift (whose Optional is written as nil) get the same safety as Option from nil plus types, without wrapping and unwrapping at every step.

7. def and the REPL

  • The value of (def …) is the defined name, fully qualified: user.greet.
  • The REPL prints it, and on redefinition adds a comment: user.greet ; redefined. In a live environment this tells that all code already calling the function now gets the new version. The comment starts with ;, so the output stays valid Diaspar.
  • In a terminal the REPL prompts user=> and, on the continuation lines of an unfinished form, an aligned ..>. When input is piped, it prints no prompts, only results, so output is easy to compare in tests.
  • Results go to stdout, errors to stderr.
  • REPL inputs are numbered, as in Julia: a location in input 7 is REPL[7]:1:43, and (input 7) shows that input's text. Where an input defined something, the call chain names it too: user.read-config (REPL[7]:1:26).

Rejected alternatives

  • Two equality operators (= and == as in Clojure; == and === as in JavaScript and Elixir).
  • No cross-kind numeric equality ((= 1 1.0) false): forces a second operator for numbers.
  • IEEE NaN ≠ NaN for =: breaks equality of collections that contain NaN and map lookup.
  • Division by zero as an error for floats, as in Python.
  • Integer division by /, or ratios as in Clojure.
  • close? in the prelude.
  • Code points or bytes as the unit of count.
  • Swift's canonical-equivalence equality: slower, complicates hashing, and surprises.
  • nil from rest, and a separate next.
  • An Option type, or a second absence value.