-
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
34 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,32 @@ | ||
# Index expressions | ||
|
||
> **<sup>Syntax</sup>**\ | ||
> _IndexExpression_ :\ | ||
> [_Expression_] `[` [_Expression_] `]` | ||
[Array] and [Map] types can be indexed by by writing a square-bracket-enclosed expression after them. For arrays, the type of the index key has to be `u256` whereas for [Map] types it has to be equal to the key type of the map. | ||
|
||
|
||
Example: | ||
|
||
```python | ||
contract Foo: | ||
|
||
balances: Map<address, u256> | ||
|
||
pub fn baz(values: u256[10]): | ||
# Assign value at slot 5 | ||
values[5] = 1000 | ||
# Read value at slot 5 | ||
let val1: u256 = values[5] | ||
|
||
# Assign value for address zero | ||
self.balances[address(0)] = 10000 | ||
|
||
# Read balance of address zero | ||
let bal: u256 = self.balances[address(0)] | ||
``` | ||
|
||
[_Expression_]: expressions.md | ||
[Array]: array_types.md | ||
[Map]: hashmap_types.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