Skip to the content
Diaspar

Decision D008 · accepted; data literals proposed

Brackets work as in Racket: interchangeable, shape preserved

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) for interchangeable brackets and preserved shape; proposed for data-literal syntax

Decision

The reader treats (), [], and {} the same way: each pair reads as a list. A pair must match, so [a b) is a read error. This follows Racket and R6RS Scheme.

As in Racket, the reader records which bracket was used. The shape is stored as a property of the syntax object (Racket calls it paren-shape), so macros, the formatter, error messages, and tools can see it. When syntax becomes plain data (quote, or converting syntax to a datum), the shape is dropped: '[a b] and '(a b) are equal lists.

The core language and the standard library give the shape no meaning. Brackets are stylistic by convention:

  • [] for bindings, parameters, and clauses;
  • () for calls and special forms.

The formatter keeps the brackets the author wrote.

Example

(defn total [item]                 ; [] for parameters: style only
  (let [p (get item :price)        ; [] for bindings: style only
        q (get item :qty)]
    (* p q)))

(let (p 1 q 2) (* p q))            ; reads the same: all brackets are lists
{let [p 1 q 2] (* p q)}            ; also the same, though unconventional
(let [p 1 q 2) (* p q))            ; read error: [ closed by )

;; let takes flat bindings (D009)

Data literals (proposed)

Because [] and {} are lists, they cannot denote vectors and maps as in Clojure. Proposal: data literals with a # prefix.

#[1 2 3]            ; vector
#{:price 10 :qty 2} ; map
#set[:a :b]         ; set

Racket writes #(1 2 3) for vectors and #hash((a . 1)) for hash tables; the exact spelling for Diaspar is still open.

Why

  • Readability without new meaning. Bindings and clauses stand out, as in Racket, while the code stays one uniform structure for macros and code generation.
  • Earlier error detection. Matching pairs catch broken structure at read time instead of at a confusing place later.
  • Preserving the shape costs nothing and helps tools. The formatter can keep the author's style, error messages can quote the code as written, and a macro that wants to offer a special notation can do so, as in Racket.

Rejected alternatives

  • Clojure style: each bracket has its own meaning ([] vector, {} map). Convenient data literals, but the brackets stop being stylistic.
  • Only (), as in R7RS Scheme and Common Lisp. Uniform, but harder to read.
  • Interchangeable brackets with the shape thrown away. Simpler reader, but tools and macros lose information Racket finds useful.

Open questions

  • The exact data-literal syntax (#[] / #{} / #set[], Racket's #(...), or functions such as (vector 1 2 3) only).
  • Whether user macros that give the shape a meaning should be allowed freely, as in Racket, or flagged by a lint.
  • Whether {} gets its own convention (for example, keyword-argument groups) or stays unused by convention.