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