Skip to content

5.3. Primary Expressions#

Syntax#


(* Introduced in 0.5.3 *)
TypeExpression = (* type_keyword: *) TYPE_KEYWORD
(* open_paren: *) OPEN_PAREN
(* type_name: *) TypeName
(* close_paren: *) CLOSE_PAREN;

NewExpression = (* new_keyword: *) NEW_KEYWORD
(* type_name: *) TypeName;

TupleExpression = (* open_paren: *) OPEN_PAREN
(* items: *) TupleValues
(* close_paren: *) CLOSE_PAREN;

TupleValues = (* item: *) TupleValue ((* separator: *) COMMA (* item: *) TupleValue)*;

TupleValue = (* expression: *) Expression?;

ArrayExpression = (* open_bracket: *) OPEN_BRACKET
(* items: *) ArrayValues
(* close_bracket: *) CLOSE_BRACKET;

ArrayValues = (* item: *) Expression ((* separator: *) COMMA (* item: *) Expression)*;

Array Literals#

An array literal is a comma-separated list of one or more expressions, enclosed in square brackets ([...]). For example [1, a, f(3)]. It is always a statically-sized memory array whose length is the number of expressions.

contract MyContract {
    function someFunction() public pure {
        otherFunction([uint(1), 2, 3]);
    }
}

Array Slices#

Array slices are a view on a contiguous portion of an array. They are written as x[start:end], where start and end are expressions resulting in a uint256 type (or implicitly convertible to it). The first element of the slice is x[start] and the last element is x[end - 1].

Both start and end are optional: start defaults to 0 and end defaults to the length of the array.

Note

This section is under construction. You are more than welcome to contribute suggestions to our GitHub repository.