help-jel
[Top][All Lists]
Advanced

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

Re: Array casts


From: Konstantin L. Metlov
Subject: Re: Array casts
Date: Thu, 22 Apr 2021 15:20:20 +0300
User-agent: SquirrelMail/1.4.23 [SVN]

Dear Mark,

Yes, JEL does not support explicit casting to array types.

In principle this can be implemented on top of JEL (as any other features
of Java programming language). But my original idea was that JEL is a
small embeddable compiler, supporting some minimal (yet complete) subset
of Java while avoiding the features, which are not absolutely necessary.

In my experience explicit casts can be completely avoided in JEL by
employing polymorphism in the static and dynamic library functions. This
will also allow the JEL compiler to detect more type mismatch errors at
compile time. In the worst case, if they can not be avoided, it is
possible to implement cast as a function.

Are you sure the explicit array casts are indeed absolutely necessary ?

With the best regards,
                          Konstantin.

> Dear Konstantin,
>
> me again.  It seems like it's not possible to cast to array types
> in JEL expressions; see the following code:
>
>     import gnu.jel.CompilationException;
>     import gnu.jel.Evaluator;
>     import gnu.jel.Library;
>
>     public class Cast {
>         public static void main( String[] args ) throws
> CompilationException {
>             Library lib = new Library(new Class[] {Cast.CLib.class},
>                                       null, null, null, null);
>             Evaluator.compile("iValue(3)", lib, null);
>             Evaluator.compile("(double) iValue(3)", lib, null);
>             Evaluator.compile("dArray(3)", lib, null);
>             Evaluator.compile("(double[]) dArray(3)", lib, null); // error
> here
>         }
>
>         public static class CLib {
>             public static int iValue(int i) {
>                 return i;
>             }
>             public static Object dArray(int n) {
>                 return new double[n];
>             }
>         }
>     }
>
> which gives me (JEL 2.1.2):
>
>     gnu.jel.CompilationException: Encountered unexpected character ']'
>
> Is there some good reason for this?  Could it be fixed so that
> array casts are possible?
>
> Many thanks,
>
> Mark
>
> --
> Mark Taylor  Astronomical Programmer  Physics, Bristol University, UK
> m.b.taylor@bristol.ac.uk          http://www.star.bristol.ac.uk/~mbt/
>
>





reply via email to

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