help-jel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-jel] Variable argument list


From: Philip Jonkergouw
Subject: [Help-jel] Variable argument list
Date: Mon, 07 Dec 2015 17:43:55 -0500

Hi,

I'm new to JEL and am considering using it for my project, so first of all, thank you for creating it! Very impressive performance benchmarks (also including my own tests).

I'm playing around in my home made JEL sandbox and have come across a problem for which I would like to find a workaround. Consider this scenario:

public class Util {
public static Object Decode(Object... b) {
if (b.length < 2) throw new IllegalArgumentException("Too few arguments.");
int i = 2;
while (i < b.length) {
if (b[0] == b[i-1]) return b[i];
i += 2;
}
return null;
}
}

public class MySandBox {
    public static void main(java.lang.String[] args) throws Throwable {
Object o = Util.Decode("Hello", "World", 2.0, "Hello", 3.0);
System.out.println("decode(\"Hello\", \"World\", 2.0, \"Hello\", 3.0): " + java.lang.String.valueOf(o));

Class[] stLib = new Class[1];
stLib[0] = Util.class;
gnu.jel.Library lib = new gnu.jel.Library(stLib,null,null,null,null);
gnu.jel.CompiledExpression expr;
expr = gnu.jel.Evaluator.compile("Decode(\"Hello\", \"World\", 2.0, \"Hello\", 3.0)",lib, java.lang.Double.TYPE);
    };
};

The error I get during execution is:

Exception in thread "main" gnu.jel.CompilationException: Function "Decode" exists but parameters "Decode(class java.lang.String,class java.lang.String,double,class java.lang.String,double)" can not be accepted by it.

I can understand why this is happening.

However, might there be a way to disable this type of checking and "simply" execute the code through the JEL library? Or could you suggest a workaround? I realise there's nothing "simple" about the inner workings of JEL, please don't get me wrong! The Java function "Decode" is meant to be extremely flexible, passing any number and types of arguments. It can handle all sorts of string comparisons, integer comparisons and return a number of types including doubles, ints and strings. Creating strongly typed overrides isn't an option.

Thanks in advance for the consideration.

Best regards,
Phil


reply via email to

[Prev in Thread] Current Thread [Next in Thread]