This project has moved and is read-only. For the latest updates, please go here.

Unlike static array literals, which can only have a restricted set of literal values as elements, a dynamic array literal may include the value of any Essence# statement as an element. To support that, the syntax of dynamic array literals must be significantly different than that of static array literals.

Here's the EBNF for dynamic array literals:

DynamicArrayLiteral = "{"  [{Statement, OptionalWhitespace, "."}, FinalStatement, ["."] "}";

A dynamic array literal must begin with a single "{" character, which may optionally be followed by a sequence of Essence# statements separated from each other by a "." character. The final statement in the sequence may optionally be followed by a "." character. The final character of a dynamic array literal must be a single "}" character.

The value of each element of the array that will be constructed by the dynamic array literal is the value of each statement in the statement sequence as specified in the dynamic array literal (in the same order, of course.) As with any Essence# array, any objects may be elements of the array, without restriction.

Here's an example of a dynamic array literal:

{3 + 4. self class. [:collection | collection reduce: [:a :b | a max: b]]. 'Foo'}


The array that will be constructed at run time by the dynamic array literal shown in the example will have the same elements as the one constructed by the following code:

| array |
array := Array new: 4.
at: 1 put: 3 + 4;
at: 2 put: self class;
at: 3 put: [:collection | collection reduce: [:a :b | a max: b]];
at: 4 put: 'Foo'.

Last edited Aug 10, 2014 at 7:08 AM by Strategesis, version 20