@@ -130,50 +130,43 @@ program test.aleo {
130130
131131### Arrays
132132
133- Leo supports static arrays. Array types are declared as ` [type; length] ` and can be nested.
134-
135- Arrays only support constant accesses. The accessor expression must be a constant expression.
136-
137- Arrays can contain primitive data types, structs, or arrays. Structs and records can also contain arrays.
138-
139- Arrays can be iterated over using a for loop.
140-
133+ Leo supports static arrays. Array types are declared as ` [type; length] ` . Elements can only be primitive data types, structs, or nested arrays.
141134``` leo
142135// Initalize a boolean array of length 4
143136let arr: [bool; 4] = [true, false, true, false];
144137
138+ // Empty array
139+ let empty: [u32; 0] = [];
140+
145141// Nested array
146142let nested: [[bool; 2]; 2] = [[true, false], [true, false]];
143+ ```
147144
148- // Empty array
149- let empty: [u32; 0] = [];
145+ Structs and records can also contain arrays as fields.
146+ ``` leo
147+ record Foo {
148+ owner: address,
149+ data: [u8; 8],
150+ }
150151
151152struct Bar {
152- data: u8 ,
153+ data: [u8; 8] ,
153154}
154155
155156// Array of structs
156157let arr_of_structs: [Bar; 2] = [Bar { data: 1u8 }, Bar { data: 2u8 }];
158+ ```
159+ Arrays can be stored as a mapping output, and iterated over using a loop.
160+
161+ ``` leo
162+ // Declare a mapping that contains array values
163+ mapping data: address => [bool; 8];
157164
158165// Access the field of a struct within an array
159166transition foo(a: [Bar; 8]) -> u8 {
160167 return a[0u8].data;
161168}
162169
163- // Struct that contains an array
164- struct Bat {
165- data: [u8; 8],
166- }
167-
168- // Record that contains an array
169- record Floo {
170- owner: address,
171- data: [u8; 8],
172- }
173-
174- // Declare a mapping that contains array values
175- mapping data: address => [bool; 8];
176-
177170// Iterate over an array using a for loop and sum the values within
178171transition sum_with_loop(a: [u64; 4]) -> u64 {
179172 let sum: u64 = 0u64;
@@ -186,22 +179,42 @@ transition sum_with_loop(a: [u64; 4]) -> u64 {
186179
187180### Tuples
188181
189- Leo supports tuples. Tuple types are declared as ` (type1, type2, ...) ` and can be nested. Tuples cannot be empty.
182+ Leo supports tuples. Tuple types are declared as ` (type1, type2, ...) ` and cannot be empty.
190183
191- Tuples only support constant access with a dot ` . ` and a constant integer .
184+ Tuples can contain primitive data types, structs, arrays, or nested tuples. Structs and records can also contain tuples .
192185
193- Tuples can contain primitive data types, structs, or arrays. Structs and records can also contain tuples.
186+ ``` leo
187+ // Initalize a boolean array of length 4
188+ let tup: (u8,u8,bool) = (1u8,1u8,true);
189+
190+ // Nested array
191+ let nested: [[bool; 2]; 2] = [[true, false], [true, false]];
192+ ```
194193
194+ Structs and records can also contain tuples as fields.
195195``` leo
196- program test.aleo {
197- transition baz(foo: u8, bar: u8) -> u8 {
198- let a: (u8, u8) = (foo, bar);
199- let result: u8 = a.0 + a.1;
200- return result;
201- }
196+ record Foo {
197+ owner: address,
198+ data: (u8,u8),
199+ }
200+
201+ struct Bar {
202+ data: (u8,u8),
202203}
204+
205+ // Tuple of structs
206+ let tup_of_structs: [Bar; 2] = [Bar { data: (1u8,1u8) }, Bar { data: (2u8,2u8) }];
203207```
204208
209+ Tuples only support constant access with a dot ` . ` and a constant integer.
210+
211+ ``` leo
212+ transition baz(foo: u8, bar: u8) -> u8 {
213+ let a: (u8, u8) = (foo, bar);
214+ let result: u8 = a.0 + a.1;
215+ return result;
216+ }
217+ ```
205218
206219### Structs
207220
0 commit comments