| 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 class Closure#main#function extends core::Object implements core::Function { | |
| 6 field core::String note = "This is temporary. The VM doesn't need closure clas
ses."; | |
| 7 field Vector context; | |
| 8 constructor •(final Vector context) → dynamic | |
| 9 : self::Closure#main#function::context = context | |
| 10 ; | |
| 11 method call() → dynamic { | |
| 12 "This is a temporary solution. In the VM, this will become an additional par
ameter."; | |
| 13 final Vector #contextParameter = this.{self::Closure#main#function::context}
; | |
| 14 return #contextParameter[1]; | |
| 15 } | |
| 16 } | |
| 17 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]; |
| 18 static method main() → dynamic { | 6 static method main() → dynamic { |
| 19 dynamic closures = <dynamic>[]; | 7 dynamic closures = <dynamic>[]; |
| 20 for (core::int i in self::numbers) { | 8 for (core::int i in self::numbers) { |
| 21 final Vector #context = MakeVector(2); | 9 final Vector #context = MakeVector(2); |
| 22 #context[1] = i; | 10 #context[1] = i; |
| 23 { | 11 { |
| 24 closures.add(new self::Closure#main#function::•(#context)); | 12 closures.add(MakeClosure<() → dynamic>(self::closure#main#function, #conte
xt)); |
| 25 } | 13 } |
| 26 } | 14 } |
| 27 core::int sum = 0; | 15 core::int sum = 0; |
| 28 for (core::Function f in closures) { | 16 for (core::Function f in closures) { |
| 29 sum = sum.+(f.call()); | 17 sum = sum.+(f.call()); |
| 30 } | 18 } |
| 31 core::int expectedSum = self::numbers.length.-(1).*(self::numbers.length).~/(2
); | 19 core::int expectedSum = self::numbers.length.-(1).*(self::numbers.length).~/(2
); |
| 32 if(!expectedSum.==(sum)) { | 20 if(!expectedSum.==(sum)) { |
| 33 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); | 21 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); |
| 34 } | 22 } |
| 35 } | 23 } |
| 24 static method closure#main#function(Vector #contextParameter) → dynamic { |
| 25 return #contextParameter[1]; |
| 26 } |
| OLD | NEW |