help-jel
[Top][All Lists]
Advanced

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

[Help-jel] Dynamic vs. static variable namespace clash


From: Mark Taylor
Subject: [Help-jel] Dynamic vs. static variable namespace clash
Date: Thu, 19 Oct 2017 14:27:22 +0100 (BST)
User-agent: Alpine 2.21 (LRH 202 2017-01-01)

Dear Konstantin,

I have dynamic variables with the same name as static functions,
and in some, but not all, cases it means that JEL expressions
can't access the static functions.

Where the dynamic variables are defined using named methods of
the dynamic library class, it works OK.  But where the dynamic
variables are defined via a DVMap implementation, the dynamic
variable seems to mask the static method, and I get a
CompilationException.

There is an example in the attached program.  I've imported
java.lang.Math as a class supplying static methods, so the
static methods sin(double) and cos(double) are defined.
Then I have one dynamic class with a method "sin()" and
another dynamic class with a method getDoubleProperty(String name)
with a corresponding DVMap getTypeName method that returns a
value for name=="cos".

With this setup the JEL expression "sin" gives me the value from
the dynamic class and "sin(x)" invokes the static method from
java.lang.Math, which is what I want to happen.
But while the JEL expression "cos" works as an alias for
getDoubleProperty("cos") as expected, "cos(x)" instead gives 
me a CompilationException with the message:

    Dynamic variable can't have the formal parameters.

The program output looks like this:

   19+1 = 20
   sin = 23.0
   sin(1) = 0.8414709848078965
   getDoubleProperty("cos") = 5.0
   cos = 5.0
   cos(1) FAIL [gnu.jel.CompilationException: Dynamic variable can't have the 
formal parameters.]

It seems like this doesn't need to happen, since the two invocations
could be distinguished by their signatures (which is presumably
what happens in the sin case).

On the other hand, I see in the "Dynamic variables interface" chapter 
of the documentation this sentence:

   "If there is conflict between the dynamic variable name and
    other name in JEL namespace the dynamic variable has a priority."

which I suppose means that it is behaving as documented.

So, my question is: is there some way I can avoid this happening
in my code (i.e. allow "cos(1)" to work in the above example),
and failing that, is it something that might get fixed in a future 
JEL version?

If there's some way round it, great.  But if not, that's fine too -
JEL is working extremely well for me 99.9% of the time, and if
necessary I'll just work round this by defining static methods
with names that are not very likely to clash with (the uncontrolled
vocabulary of) dynamically available names.

Best wishes and many thanks for your work,

Mark

--
Mark Taylor   Astronomical Programmer   Physics, Bristol University, UK
address@hidden +44-117-9288776  http://www.star.bris.ac.uk/~mbt/

Attachment: Vars.java
Description: test program


reply via email to

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