-
Notifications
You must be signed in to change notification settings - Fork 2
Arrays and Objects
A pair of curly braces, square braces, or parentheses can contain either a list of statements or a list of key-value pairs. Each statement or pair can, but does not have to, be separated by a comma or semicolon. A colon must be placed between a key and its corresponding value. For example, the following is an object:
{
base: carrot_on_a_stick
name: "my item"
}
and the following is an array:
{1, 2, "fizz", 4, "buzz"}
Arrays are often used to group multiple commands together into a function or block if they are meant to be run in sequence.
The parser will assume something is a list even if it has only one element that's not a valid key-value pair. This may lead to confusing error messages.
The order that items of an object will be evaluated are not guaranteed, as they are internally represented by a map. The order that items of an array will be evaluated is guaranteed to be the order in which they appear.
Internally, the compiler uses the same representation for a key-value pair as an operation. When deciding if an array can be coerced into an object, the parser makes sure the left side is an identifier and the operation is a colon.