I am writing this library for manipulating exponential families, bregman divergences, and so on.
I am using Java. Today, I discovered that Java can handle arbitrary number of parameters using the three dots ... syntax as follows:
class VarargsSum
{
public static double cumul(double... elements)
{
double cumul=0.0d;
for (double el:elements)
cumul+=el;
return cumul;
}
public static void write(String... records)
{
for (String record: records)
System.out.println(record);
}
public static void main(String [] args)
{
Double sum=cumul(5.0,4.0,23.0);
write("Computational","Information","Geometry",sum.toString());// explicit cast needed
}
}
Compiling and running this above code, you will get
Computational
Information
Geometry
32.0
Let me see how to best use this in the library now...
Frank.
I am writing this library for manipulating exponential families, bregman divergences, and so on. I am using Java. Today, I discovered that Java can handle arbitrary number of parameters using the three dots ... syntax as follows:
class VarargsSum { public static double cumul(double... elements) { double cumul=0.0d; for (double el:elements) cumul+=el; return cumul; } public static void write(String... records) { for (String record: records) System.out.println(record); } public static void main(String [] args) { Double sum=cumul(5.0,4.0,23.0); write("Computational","Information","Geometry",sum.toString());// explicit cast needed } }Compiling and running this above code, you will get
Let me see how to best use this in the library now... Frank.