Closures work

This commit is contained in:
2022-08-26 03:54:58 +01:00
parent 0c67ce6476
commit ffc50ceafb
4 changed files with 62 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
fn name(param1: string, param2: string): string {
/*
fn name(param1: string, param2: string, param3): string {
print "foobar";
print param1;
return param2;
@@ -10,3 +10,42 @@ var result = name("hello world", "goodnight world");
print "fizz";
print result;
print "buzz";
*/
/*
fn outer() {
fn inner() {
print "foo";
}
inner();
return inner;
}
var handle = outer();
handle(); //breaks
*/
fn make() {
var counter = 0;
fn count() {
return counter++;
}
return count;
}
var tally = make();
print tally();
print tally();
print tally();
print tally();
print tally();