OLD | NEW |
1 library; | 1 library; |
2 import self as self; | 2 import self as self; |
3 import "dart:core" as core; | 3 import "dart:core" as core; |
4 | 4 |
5 static const field dynamic numbers = const <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8
, 9]; | 5 static const field dynamic numbers = const <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8
, 9]; |
6 static method main() → dynamic { | 6 static method main() → dynamic { |
7 dynamic closures = <dynamic>[]; | 7 dynamic closures = <dynamic>[]; |
8 final Vector #context = MakeVector(3); | 8 final dynamic #context = MakeVector(3); |
9 #context[2] = 0; | 9 #context[2] = 0; |
10 for (core::int i in self::numbers) { | 10 for (core::int i in self::numbers) { |
11 final Vector #context = MakeVector(3); | 11 final dynamic #context = MakeVector(3); |
12 #context[1] = #context; | 12 #context[1] = #context; |
13 #context[2] = i; | 13 #context[2] = i; |
14 { | 14 { |
15 closures.add(MakeClosure<() → dynamic>(self::closure#main#function, #conte
xt)); | 15 closures.add(MakeClosure<() → dynamic>(self::closure#main#function, #conte
xt)); |
16 } | 16 } |
17 } | 17 } |
18 core::int sum = 0; | 18 core::int sum = 0; |
19 for (core::Function f in closures) { | 19 for (core::Function f in closures) { |
20 sum = sum.+(f.call()); | 20 sum = sum.+(f.call()); |
21 } | 21 } |
22 core::int expectedSum = self::numbers.length.-(1).*(self::numbers.length).~/(2
); | 22 core::int expectedSum = self::numbers.length.-(1).*(self::numbers.length).~/(2
); |
23 if(!expectedSum.==(sum)) { | 23 if(!expectedSum.==(sum)) { |
24 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); | 24 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); |
25 } | 25 } |
26 } | 26 } |
27 static method closure#main#function(Vector #contextParameter) → dynamic { | 27 static method closure#main#function(dynamic #contextParameter) → dynamic { |
28 return (#contextParameter[2]).+(#contextParameter[1][2]); | 28 return (#contextParameter[2]).+(#contextParameter[1][2]); |
29 } | 29 } |
OLD | NEW |