Schemas
Schemas are abstract data structures that contain one or more member variables.
Records are instantiated objects defined by schemas.
Declaration
Schema declaration provides an ordered collection of associations between keys and types.
Person {
Name :sequence
Age :natural
_ :natural
}
As constant expressions, member types may resolve from values, variables, or the types of other objects.
User {
Id :natural
}
Message {
User :User.Id
}
Instantiation
Instantiation creates a record object described by a schema.
Person.{
Name: "Guy"
Age: 27
}
Derived Instantiation
Derived instantiation uses an existing schema instance as the basis for a new record.
Template: Person.{ Age: 51 }
Data: Template.{ Name: "Tsunade" }
expect(Data, "{Name:Tsunade,Age:51}")
Table Instantiation
Table instantiation, denoted by the |=|
operator, generates an array of records corresponding to table rows.
When defining a global variable from a table, the definition indicator :
may be omitted from the expression.
Table construction does not require that all members be defined—any members not present in the table are constructed with default values.
People |=|Person {
| Name | Age |
| "Hayate" | 16 |
| "Nagi" | 13 |
| "Maria" | 17 |
| "Hinagiku" | 15 |
}
Default Values
Empty table cells will be initialized with the default value for their type.
Rows |=|Row {
|Key |Value |
|"A" |1 |
|"B" | |
}
expect(Rows[0], "{Key:A,Value:1}")
expect(Rows[1], "{Key:B,Value:0}")
Repeat Values
A table cell starting with the repeat indicator :
will be prefixed with the expression of the previous row.
The repeat indicator is treated as a subexpression, allowing the expression to be extended.
Rows |=|Row {
|Key |Value |
|"A" |1 |
|"B" |: |
|"C" |:+1 |
}
expect(Rows[0], "{Key:A,Value:1}")
expect(Rows[1], "{Key:B,Value:1}")
expect(Rows[2], "{Key:C,Value:2}")
Output Columns
Output columns construct variables containing table metadata.
People |=|Person {
| + | & | Name | Age |
| First | Hayate | "Hayate" | 16 |
| | Nagi | "Nagi" | 13 |
| | Maria | "Maria" | 17 |
| Last | Hinagiku | "Hinagiku" | 15 |
}
expect(People[People.First], "{Name:Hayate,Age:16}")
expect(People.Maria, "{Name:Maria,Age:17}")
Enumeration
Enumeration columns are indicated by the +
operator and produce global variables containing row indices.
Reference
Reference columns are indicated by the &
operator and produce variables containing references to row data.
The locality of reference variables is tied to the locality of the table.