Literal arrays are special expressions that evaluate as arrays. They provide an easy way to create a vector and to initialize its items.
Literal arrays are delimited by brackets, and they contain zero or more expressions inside the brackets and separated by commas.
['once', 'twice', 'thrice']
Note that no explicit type is provided for the literal. On the contrary, the expression type is inferred from the item types. However, you can use an array literal as a collection initializer in an explicit array creation expression:
new Array[String]!['a', 'b', 'c']
The literal array is an array of characters, but the whole expression is considered as an array of strings.
Literal array may not evaluate always all their items. When a literal array is used in the right operand of a membership test, the test may be translated as a chain of equality checks:
// Original test expression in [item1, item2, item3] // Generated code var temp = expression; temp = item1 or temp = item2 or temp = item3
In this case, the generated code uses short-circuit evaluation. If some item contains a method call, it may not be executed at all.
Literal arrays can also be used as the collection in for/in statements:
for var s in ['One', 'Two', 'Three', 'O''Clock'] do Console.WriteLine(s);
In this case, the compiler knows beforehand the numbers of items in the array, so it can apply some optimizations to the generated code.
The Freya Programming Language
Expressions
Literal constants
Instantiation
Constructors
Array types