glox/tests/functions.lox
2024-10-11 17:01:12 +03:00

44 lines
No EOL
585 B
Text

print "native function";
print clock();
fun count(n) {
if (n > 1) count(n - 1);
print n;
}
count(10);
fun hi(name, surname) {
print "hello, " + name + " " + surname + "!";
}
hi("John", "Doe");
fun re(turn) {
print "before return";
return turn;
print "should not be printed";
}
print re("turn");
fun sum(start, end) {
if (start == end) return start;
return start + sum(start + 1, end);
}
print sum(1, 3);
fun fib(n) {
if (n <= 1) return n;
return fib(n - 2) + fib(n - 1);
}
for (var i = 1; i <= 10; i = i + 1) {
print fib(i);
}