Function Calls

Functions are packets of statements that can be used repeatedly. They can accept any number of inputs and can return any number of outputs.

The name of a function must be a valid identifier. If a function name is the same as a variable name, the variable name takes precedence. Similarly, if a user-defined function and built-in function have the same name, the user-defined function takes precedence.

Inputs are passed to a function using ()’s. They are separated by ,’s.
my_function(input1, input2, …, inputN)
If a function can be called without inputs, the ()’s are optional.
Inputs can be any valid expression.
sqrt(1+b/3*5^2) % assuming b is a valid variable

If the number of inputs passed to a function does not match the number expected by that function, an error occurs.

If a function returns a single value, this return value can be used in other expressions.
sum(sqrt(1)+sqrt(2))
It can also be assigned to a variable.
output = sqrt(1)
If a function returns multiple values, each return value must be assigned to a distinct variable. The output variables are grouped using [ ]’s and separated by ,’s (or optionally spaces).
[out1, out2] = f(in1, in2)
function [len,first] = info(x)
      len = length(x);
      first = x(1);
end

[a,b] = info([4,8,2,9])

Unlike single return function calls, multi-return function calls cannot be directly combined with other operators.

If a function returns more outputs than are assigned, the remainder is ignored. If a function returns fewer outputs than are assigned, an error occurs.

Each function has its own rules as to what constitutes valid inputs. OML language supports an alternate function syntax. String arguments can be passed to a function without using ()’s and by using spaces instead of commas to separate them. These two calls are equivalent:
myfunc('hello','goodbye')
myfunc hello goodbye

OML language has many built-in functions that are directly callable. These will be cataloged in a separate document. You can also define you own functions (see Function Definitions).