Closures 25
This commit is contained in:
parent
1a614ac45b
commit
dc4e6d33b2
16 changed files with 422 additions and 209 deletions
|
|
@ -19,11 +19,12 @@ void main(){
|
|||
|
||||
"./test/ops.lox".match("1\n2\n3\n4\n5\n6\n7\ntrue\nfalse\ntrue\ntrue\nhello, world\n");
|
||||
"./test/shortcircuit.lox".match("true\nAAAA!\nAAAA!\nAAAA?\n");
|
||||
/* "./test/closure.lox".match("1\n2\n"); */
|
||||
"./test/closure.lox".match("1\n2\n");
|
||||
"./test/scope.lox".match("global first first second first ".replace(' ', '\n'));
|
||||
"./test/fib_for.lox".match(fib(6765));
|
||||
"./test/fib_recursive.lox".match(fib(34));
|
||||
/* "./test/fib_closure.lox".match(fib(34)); */
|
||||
"./test/fib_closure.lox".match(fib(34));
|
||||
"./test/perverseclosure.lox".match("return from outer create inner closure value ".replace(" ", "\n"));
|
||||
/* "./test/class.lox".match("The German chocolate cake is delicious!\n"); */
|
||||
/* "./test/super.lox".match("Fry until golden brown.\nPipe full of custard and coat with chocolate.\nA method\n"); */
|
||||
|
||||
|
|
|
|||
18
test/perverseclosure.lox
Normal file
18
test/perverseclosure.lox
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
fun outer(){
|
||||
var x = "value";
|
||||
fun middle(){
|
||||
fun inner(){
|
||||
print x;
|
||||
}
|
||||
print "create inner closure";
|
||||
return inner;
|
||||
}
|
||||
print "return from outer";
|
||||
return middle;
|
||||
}
|
||||
|
||||
var mid = outer();
|
||||
var in = mid();
|
||||
in();
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue