Skip to content

Commit

Permalink
spec: cover list expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf committed Aug 23, 2021
1 parent e0e810a commit 890484c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [Expressions](spec/expressions.md)
* [Call expressions](spec/expr_call.md)
* [Tuple expressions](spec/expr_tuple.md)
* [List expressions](spec/expr_list.md)
* [Attribute expressions](spec/expr_attribute.md)
* [Literal expressions](spec/expr-literal.md)
* [Arithmetic Operators](spec/arithmetic_operators.md)
Expand Down
39 changes: 39 additions & 0 deletions docs/src/spec/expr_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# List expressions

> **<sup>Syntax</sup>**\
> _ListExpression_ :\
> &nbsp;&nbsp; `[` _ListElements_<sup>?</sup> `]`
>
> _ListElements_ :\
> &nbsp;&nbsp; [_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
1 change: 1 addition & 0 deletions docs/src/spec/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* [Expressions](expressions.md)
* [Call expressions](expr_call.md)
* [Tuple expressions](expr_tuple.md)
* [List expressions](expr_list.md)
* [Attribute expressions](expr_attribute.md)
* [Literal expressions](expr-literal.md)
* [Arithmetic Operators](arithmetic_operators.md)
Expand Down

0 comments on commit 890484c

Please sign in to comment.