Skip to content

Records

Anonymous structs with named fields:

user = { name = "Alice", age = 30 }
n = user.name

Fields may hold any type — Text, arrays, nested arrays, etc. — and read back at their real type (no numeric-only restriction). (See examples/records.qn and examples/composites.qn, which exercises a Text record field, an array of Text, and a nested array together.)

Methods take an implicit it (the receiver):

User = {
name :: Text,
age :: Num,
greet = => "Hello, " + it.name,
olderBy = years => it.age + years
}
u = User { name = "Alice", age = 30 }
g = u.greet() ~ "Hello, Alice"
a = u.olderBy(5) ~ 35

(See examples/methods.qn.)

A method declared with := instead of = is a setter — it may mutate its receiver — and calling one requires a mutable (:=) receiver (see Mutation).

An unannotated method parameter defaults to Num (as in any ordinary definition), and call sites are held to that default: t.add("hi") on add = (x) => it.v + x is a type error, not a runtime surprise.