SPLASH Functions

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.

Note: You can also write your own functions in C/C++ or Java. Consult the reference information for details on building libraries and calling them from within the Event Stream Processor.
The syntax for declaring SPLASH functions resembles C. In general, a function looks like
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.
Here is an example of a recursive function:
integer factorial(integer x) {
   if (x <= 0) {
     return 1;
   } else {
     return factorial(x-1) * x;
   }
 }
Here is an example of two mutually recursive functions (a particularly inefficient way to calculate the evenness or oddness of a number):
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.
The next two functions illustrate multiple arguments and record input.
integer sumFun(integer x, integer y) {
  return x+y;
}
string getField([ integer k; | string data;] rec) {
  return rec.data;
}
The real use of SPLASH functions is to define a computation once. Suppose you have a way to compute the value of a bond based on its current price, its days to maturity, and forward projections of inflation. You might write a function and use it in many places within the project:
float bondValue(float currentPrice,
                 integer daysToMature,
                 float inflation) 
{
  ... 
}