Re: Variable argument list
Mark Taylor <[email protected]> Fri, 18 Dec 2015 13:10:48 +0000 (GMT)
| Newsgroups | gmane.comp.java.jel.general |
|---|---|
| Message-ID | <[email protected]> |
Philip,
I don't have a solution to this problem, but I'd really like to be
able to use variable-length argument lists functions with JEL too.
In the "PLANNED FEATURES" section of the release notes for JEL 2.0.2
(http://www.gnu.org/software/jel/RELNOTES) it says:
1. Allowing to call methods with variable number of arguments in JEL
expressions.
which I think means it currently won't do that. In case Konstatin
is listening: it would be great to see this in the (forseeable?)
future.
I'm a long time and extremely satisfied customer of JEL
(it forms the basis of the expression language in TOPCAT
http://www.star.bristol.ac.uk/~mbt/topcat/, widely used by
astronomers for analysis of catalogue data). In case
Konstatin is listening again - many thanks for this excellent library.
Mark
On Mon, 7 Dec 2015, Philip Jonkergouw wrote:
> 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
--
Mark Taylor Astronomical Programmer Physics, Bristol University, UK
[email protected] +44-117-9288776 http://www.star.bris.ac.uk/~mbt/