Functions take a set number of arguments

This commit is contained in:
2022-08-26 12:48:10 +01:00
parent f36289786e
commit 7bd67765aa
6 changed files with 72 additions and 58 deletions

32
test/functions.toy Normal file
View File

@@ -0,0 +1,32 @@
//test function return
fn testFourtyTwo() {
return 42;
}
assert testFourtyTwo() == 42, "function returns failed";
//test function parameters
fn identity(x) {
return x;
}
assert identity("hello world") == "hello world", "identity function failed";
//test closures
fn make() {
var counter = 0;
fn count() {
return ++counter;
}
return count;
}
var tally = make();
assert tally() == 1 && tally() == 2, "Closures failed";
print "All good";