-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# List expressions | ||
|
||
> **<sup>Syntax</sup>**\ | ||
> _ListExpression_ :\ | ||
> `[` _ListElements_<sup>?</sup> `]` | ||
> | ||
> _ListElements_ :\ | ||
> [_Expression_] (`,` [_Expression_])<sup>*</sup> `,`<sup>?</sup> | ||
A *list expression* constructs [array values]. | ||
|
||
The syntax for list expressions is a parenthesized, comma separated list of expressions, called the *list initializer operands*. The number of list initializer operands must be equal to the static size of the array type. The types of all list initializer operands must conform to the type of the array. | ||
|
||
Examples of tuple expressions and their types: | ||
|
||
| Expression | Type | | ||
| -------------------- | ------------ | | ||
| `[1, self.get_number()]` | `u256[2]` | | ||
| `[true, false, false]` | `bool[3]` | | ||
|
||
An array item can be accessed via an [index expression]. | ||
|
||
Example: | ||
|
||
```python | ||
contract Foo: | ||
|
||
fn get_val3() -> u256: | ||
return 3 | ||
|
||
pub fn baz(): | ||
let val1: u256 = 2 | ||
# A list expression | ||
let foo: u256[3] = [1, val1, self.get_val3()] | ||
``` | ||
|
||
[_Expression_]: expressions.md | ||
[array values]: array_types.md | ||
[index expression]: expr_index.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters