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 method doit(core::int x) → void { | 5 static method doit(core::int x) → void { |
6 final dynamic #context = MakeVector(3); | 6 final dynamic #context = MakeVector(3); |
7 #context[2] = x; | 7 #context[2] = x; |
| 8 x = null; |
8 final core::int max = 10; | 9 final core::int max = 10; |
9 final core::double expectedSum = max.-(1).*(max)./(2); | 10 final core::double expectedSum = max.-(1).*(max)./(2); |
10 core::int counter = 0; | 11 core::int counter = 0; |
11 dynamic calls = <dynamic>[]; | 12 dynamic calls = <dynamic>[]; |
12 while (counter.<(max)) { | 13 while (counter.<(max)) { |
13 final dynamic #context = MakeVector(3); | 14 final dynamic #context = MakeVector(3); |
14 #context[1] = #context; | 15 #context[1] = #context; |
15 #context[2] = counter; | 16 #context[2] = counter; |
16 calls.add(MakeClosure<() → dynamic>(self::closure#doit#function, #context)); | 17 calls.add(MakeClosure<() → dynamic>(self::closure#doit#function, #context)); |
17 counter = counter.+(1); | 18 counter = counter.+(1); |
18 } | 19 } |
19 core::double sum = 0.0; | 20 core::double sum = 0.0; |
20 for (dynamic c in calls) | 21 for (dynamic c in calls) |
21 sum = sum.+(c.call()); | 22 sum = sum.+(c.call()); |
22 if(!sum.==(expectedSum)) | 23 if(!sum.==(expectedSum)) |
23 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); | 24 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); |
24 } | 25 } |
25 static method main() → void { | 26 static method main() → void { |
26 self::doit(0); | 27 self::doit(0); |
27 } | 28 } |
28 static method closure#doit#function(dynamic #contextParameter) → dynamic { | 29 static method closure#doit#function(dynamic #contextParameter) → dynamic { |
29 return (#contextParameter[2]).+(#contextParameter[1][2]); | 30 return (#contextParameter[2]).+(#contextParameter[1][2]); |
30 } | 31 } |
OLD | NEW |