Groovy function signatures

3.42K viewsScripting
0

Hi, just wanted to definitively confirm one way or the other:

I believe for a groovy function to be picked up by Quantrix, its parameters and return types have to be marked specifically as one of String or double (or int, Date etc.). Am I correct in saying we can’t yet define a polymorphic function in groovy that will work as Quantrix function? I.e. I would like a function to take an Object as input and return an Object (which would typically be either a String or a double).

Also I don’t think that varargs work for groovy functions? I.e. a function that accepts a variable number of input arguments.

Thanks.

0

Great, many thanks Ben. Another feature request for your database then!

0

Hi Apollo,

It’s true that functions cannot currently take or return instances of [font=””Courier New””]Object[/font]. You [i:3mgpv4h4]can[/i:3mgpv4h4] write a varargs function, but when invoking it from within a formula you have to wrap the argument list using the Quantrix [font=””Courier New””]list[/font] function. Here is an example:

Function:
[code:3mgpv4h4]
public double mySum(double... args)
{
double result = 0;
args.collect{result += it}
return result
}
[/code:3mgpv4h4]

Use in a formula, no arguments:
[code:3mgpv4h4]
A1:B1 = mySum(list())
[/code:3mgpv4h4]

Use in a formula, with arguments:
[code:3mgpv4h4]
A1:B1 = mySum(list(2, 1, 6))
[/code:3mgpv4h4]

Hope this helps.
-Ben

Latest Questions