syntax array_initialization from "<" Arg(<type>, type) ">[" [{Arg(<expr>, elems) "," [s]} Arg(<expr>, elems)] "]" {
let res = arr<$type>();
@elems.i {
res.push($elems.i);
}
return move(res);
}
syntax list_comprehension from "[" [s] Arg(<expr>, map) s "for" s Arg(<ident>, it) [s] ":" [s] Arg(<type>, type) s "in" s Arg(<expr>, container) [s] "]" {
let res = arr<$type>();
let func = ($it: $type) -> $type $map;
for _it_ in $container {
res.push(func(*_it_));
\}
return move(res);
}
let array = [i * 2 for i: Int in <Int>[1, 2, 3, 4, 5]];
if array[0] != 2 { panic("Invalid value"); }
if array[1] != 4 { panic("Invalid value"); }
if array[2] != 6 { panic("Invalid value"); }
if array[3] != 8 { panic("Invalid value"); }
if array[4] != 10 { panic("Invalid value"); }