-
Notifications
You must be signed in to change notification settings - Fork 1
Functions
Frederik Tobner edited this page Dec 17, 2022
·
8 revisions
A function call expression looks in cellox the same as it does in C.
foo(1);
Function definitions in cellox use the fun keyword and can return different types by the same function. A practical example would be a function that returns a number, or a boolean.
fun foo(number)
{
if(a >= 0)
return false;
return number ** 0.5; // Returns the square root of the number
}
Function declarations are statements, which gives you the ability to declare a local function inside another function.
fun fibonacci()
{
var x = 0;
var temp = 0;
var b = 1;
fun number()
{
temp = x;
x = b;
b = temp + x;
return temp;
}
return number;
}
var fibo = fibonacci();
for (var j = 0; j < 10; j += 1)
printf("{}\n", fibo());