Language

Functions

Typed parameters, local variables, an optional return. The return type may introduce itself with returning. It does not have to. I trust you. Mostly.

Define

define func compare(num y, decimal z);
    if y sameas z;
        return true;
    else;
        return false;
    end;
end;
  • func opens the signature.
  • Each parameter is type name, comma-separated, like a guest list.
  • end; closes the function — after any inner if has said goodbye first.

returning

Optional. Write the type after the parameter list if you want it on the door. Skip it, and the variable you assign the result to must already be the right type.

define func sub(num x, num y) returning num;
  return x - y;
end;

define func add(num x, num y);
  return x + y;
end;

define num z is call sub(x, y);
define num k is call add(x, y);

Keyword: returning.

Call

define boolean isTheSame is call compare(50, 50.0);
showln isTheSame;
call countdown(5);

call can stand alone or sit on the right of is. Methods on an object use a dot: call jacob.Birthday();. She does not mind either way.

Local scopes

Names created inside a function live there. Outer variables can still be read and redefined — a global counter, for example. Arrays passed in can be pushed and popped. They remember.

Recursion

A function may call itself, if it knows when to stop. The examples also use a for countdown, which is recursion’s more organized cousin.