CCL contains a large number of built-in functions, all of which can be used in SPLASH expressions. You can also write your own functions in SPLASH. They can be declared in global blocks for use by any stream, or local blocks for use in one stream. Functions can internally call other functions, or call itself recursively.
type functionName(type1 arg1, ..., typen argn) { ... }
where each "type" is a SPLASH type,
and each arg is the name of an argument.
The body of the function is a block of statements,
which can start with variable declarations.
The value returned by the function is the value
returned by the return statement within.
integer factorial(integer x) {
if (x <= 0) {
return 1;
} else {
return factorial(x-1) * x;
}
}
string odd(integer x) {
if (x = 1) {
return 'odd';
} else {
return even(x-1);
}
}
string even(integer x) {
if (x = 0) {
return 'even';
} else {
return odd(x-1);
}
}
Unlike C,
you do not need a prototype of the "even" function
in order to declare the "odd" function.
integer sumFun(integer x, integer y) {
return x+y;
}
string getField([ integer k; | string data;] rec) {
return rec.data;
}
float bondValue(float currentPrice,
integer daysToMature,
float inflation)
{
...
}