Skip to the content
Diaspar

Decision D029 · accepted; details proposed

One dot for members: modules, types, fields

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-16); it replaces the / separator of D011 and the keyword-function field access of D010 as the main form. Details marked proposed are not yet confirmed.

Decision

a.b means "the member b of a", with one meaning for every kind of a: a module's item, a type's variant or implementation, a record's field, a map's value. A module is the collection of its items, a type of its variants, a record of its fields, as a file is a struct in Zig and a package is a namespace in Go.

(use std.time)
(use std.term.color [Color])

(def start (time.monotonic))          ; an item of the module time
(style.fg (Color.Red))                ; a variant of the enum Color
(Config.from-json data)               ; Config's implementation of from-json
order.customer.address.city           ; fields, in a chain
math.pi                               ; a constant of a module
(map .name users)                     ; .name alone is the function that reads the field

Rules

  1. a.b is the member b of a. The expander knows at compile time what a is: a module gives its item, a type its variant or the implementation of an imported protocol method, a record value its field, a map value the value under the keyword :b.
  2. Paths use the dot. (use std.term.style); a full path works without an import, std.term.style.parse. The file src/geom/shapes.dias is the module geom.shapes, as in Python and Ferron. Package exports name modules the same way, "geom.shapes.*" (D025).
  3. No ambiguity: a local may not hide a name introduced by use. In a file with (use std.json), (let [json …] json.parse) is an error, "local json hides module json". So json.parse always means one thing, found from the use lines; Go allows this shadowing silently, Diaspar does not. The rule covers only names the file imports or aliases with use (accepted, 2026-11-16): a module the file does not import forbids nothing, so a local may be called time or repl where std.time or std.repl is not used.
  4. Fields. p.x, and chains order.customer.address.city instead of (-> order :customer :address :city).
    • A record without the field: a warning at compile time when the record's type is known, and a run-time error, at the same point in the interpreter and the compiler (accepted, 2026-11-16; types only warn, D007, as unknown names in D015).
    • A map without the key: an error, not nil, naming the path (cfg.server.port: no key :port). An optional value is read explicitly: (get cfg :port 8080).
    • A field holding a function is called as any value: (p.on-click event).
  5. .name alone is an accessor function, (fn [v] v.name), with the same strict rules: (map .name users), and the field of a call's result, (.hp (player-state)), which a.b cannot express. 6a. Keywords are not functions (accepted, 2026-11-16): Clojure's (:x m), which returns nil for a missing key, is removed, so there is one way to read a field and it is strict. An optional value is read with (get m :x default); a key computed at run time with (get m k) or the strict (fetch m k).
  6. A type is a namespace for its variants (Color.Red, D010 §3b; a variant without fields is the value itself, (style.fg Color.Red), since §3c of 2026-11-18, for the next migration wave) and for the protocol methods it implements: (Config.from-json data) calls Config's implementation of from-json from an imported protocol, as Rust's Config::from_json(data); this replaces (json.Codec.from-json Config data) (D010 §5a), which stays valid. If two imported protocols give Config a from-json, it is an error listing both.
  7. Namespaced keywords use the dot too: :cli.doc, :cli.kind.
  8. No method calls through the dot. (p.area) does not call the function area on p: functions stay functions, (area p) or (Shape.area p), so there is one way to call and no question of whose area it is. If p has no field area, the error says so and shows (area p). This may be revisited.

Reading

  • The reader reads a.b.c as one symbol; the expander splits it at the dots and resolves it by rule 1.
  • Numbers are unaffected: a token that starts with a digit (or a sign and a digit) is a number, so 1.5 and -0.5 are numbers. .5 is not a number; write 0.5.
  • A symbol may not end with a dot or contain two dots in a row; .. and ... are reserved.
  • / is an ordinary name, the division function; its full path is std.core./ (proposed spelling).

A dot after a closing bracket (accepted, 2026-11-17)

.name written right after ) (or ], }), with no space, reads the member of that form's value: (peek levels).spec.fields, (load-config).server.port, (first users).name. With a space it is a separate form, as before: (list (f x).y) has one argument, (list (f x) .y) two. This is the rule of a.b (no space) against a .b, extended to a closing bracket; the formatter never adds or removes that space.

  • It reads as a node that macros and quoting see, and that prints back as written.
  • @ applies after the member chain, as Rust's * after .: @(f).x is (deref (f).x).
  • (f).items[0] is not indexing: [0] is a list (D008).

Dots and macros (accepted, 2026-11-16)

  1. The scopes of a.b belong to its first segment. Hygiene (D015) resolves a by the symbol's scopes; the rest are member names looked up inside a, not in scope. A template's p.x reads the template's p, and the caller's p.x the caller's p; a template's json.parse finds json where the macro is defined.
  2. "A local may not hide a module" respects hygiene. It is an error only when the local would actually capture the reference, that is when the scopes allow it to bind the module's name; a local json introduced by a template never makes the caller's json.parse an error.
  3. Code is analyzed after expansion. The reader cannot know what a is, so it keeps a.b as one symbol, and 'a.b is a symbol as data. Structure appears after expansion: p.x becomes the core form for a field read, json.parse a reference to a global. A macro that analyzes code (free variables, renaming) works on expanded code, as Racket's local-expand; this is needed for nested macros anyway. (syntax.segments id) splits a.b.c into its parts, and (syntax.member base 'name) builds base.name keeping the scopes of base; gluing strings into symbols loses hygiene.
  4. A template reads a field with the accessor form: `(.port ~cfg), which works for any expression, such as (load-config). ~cfg.port unquotes the whole form cfg.port: it is the value of cfg.port in the macro's own code at expansion time, not a field read in the result.

Macro patterns use & for the rest ([test & body]), not Scheme's ..., so reserving .. and ... does not affect them.

Why

  • One concept instead of two. With / for names and keywords for fields, math/pi and (:x p) were different mechanisms for "something inside something". With the dot, a constant of a module and a field of a record are reached the same way, which is what Zig, Go, Python, Kotlin, Swift, and Gleam do.
  • Modern and familiar: every mainstream language reads a.b as a member; the field chain order.customer.address.city reads as data.
  • Rule 3 keeps what / gave: with /, a module path could never be confused with a value. Forbidding a local to hide a module keeps a.b unambiguous for people and agents; editors color modules and locals differently.
  • Now is the cheapest moment: the code written in Diaspar is about 6,000 lines, rewritten mechanically.

Rejected alternatives

  • / for names and . reserved (Rust's :: and ., Clojure, Koka): two separators for "a member of"; the user prefers the dot, and rule 3 removes the ambiguity the split was avoiding.
  • Gleam's split, / in use paths and . in code: two signs for one thing, and a full path becomes std/term/style.parse.
  • nil for a missing map key with the dot (JavaScript's undefined): a misspelled key silently becomes nil and fails far away.
  • A warning when a local's field read spells a module path ((let [geom …] geom.area) in a file that does not import geom): the local is the only geom the reader of that file sees, and Python, Go and JavaScript allow such shadowing silently; the dangerous case, a local hiding a module the file imports, is already an error by rule 3 (rejected, 2026-11-16).
  • Swift's and Zig's .red when the type is known: types are inferred and only warn (D007), so a name cannot depend on an inferred type.

Migration

All .dias code, the reader, the expanders of the bootstrap and of the compiler, and the docs move from / paths and :ns/key keywords to the dot in one change, while no other branch is open.