Records

Records are data structures that have a fixed set of keys.

You can define a record type with the record keyword:

record User {
email : String,
name : String,
id : Number
}

Record definitions are globally unique, so defining a record with the same structure but a different name will raise an error.

Nested records

Records can be nested in each other, using nested type definitions.

record Position {
x : Number,
y : Number
}
record Entity {
position : Position,
id : String
}

Creating a nested record is straightforward:

entity =
{
position = {
x = 0,
y = 0
},
id = "0"
}

Working with records

Records can be created like this:

{
email = "john.doe@gmail.com",
name = "John Doe",
id = 0
}

You can create a new record by copying from an existing one and changing only some of the fields, like this:

user =
{
email = "john.doe@gmail.com",
name = "John Doe",
id = 0
}
updatedUser =
{ user | name = "Stuart" }
{
email = "john.doe@gmail.com",
name = "Stuart",
id = 0
}

Trying to add fields to a record which doesn't have it in it's definition will raise an error.

[PLANNED] You can update a nested record with a dot notation.

user =
{
name = "Stuart",
address = {
location = "Freedonia"
}
}
{ user |
name = "Bob",
address.location = "Super Silly Fun Land"
}