Dynamic vs. static variable namespace clash
Mark Taylor <[email protected]> Thu, 19 Oct 2017 14:27:22 +0100 (BST)
| Newsgroups | gmane.comp.java.jel.general |
|---|---|
| Message-ID | <[email protected]> |
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
---561407174-1465009490-1508419644=:7742
Content-Type: text/plain; charset=US-ASCII
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
[email protected] +44-117-9288776 http://www.star.bris.ac.uk/~mbt/
---561407174-1465009490-1508419644=:7742
Content-Type: text/plain; charset=US-ASCII; name=Vars.java
Content-Transfer-Encoding: BASE64
Content-ID: <[email protected]>
Content-Description: test program
Content-Disposition: attachment; filename=Vars.java
DQppbXBvcnQgZ251LmplbC5Db21waWxhdGlvbkV4Y2VwdGlvbjsNCmltcG9y
dCBnbnUuamVsLkNvbXBpbGVkRXhwcmVzc2lvbjsNCmltcG9ydCBnbnUuamVs
LkRWTWFwOw0KaW1wb3J0IGdudS5qZWwuRXZhbHVhdG9yOw0KaW1wb3J0IGdu
dS5qZWwuTGlicmFyeTsNCmltcG9ydCBqYXZhLnV0aWwuSGFzaE1hcDsNCg0K
cHVibGljIGNsYXNzIFZhcnMgew0KDQogICAgcHJpdmF0ZSBzdGF0aWMgU3Ry
aW5nIFBST1BOQU1FID0gImNvcyI7DQoNCiAgICBwdWJsaWMgc3RhdGljIHZv
aWQgbWFpbiggU3RyaW5nW10gYXJncyApIHRocm93cyBDb21waWxhdGlvbkV4
Y2VwdGlvbiB7DQoNCiAgICAgICAgQ2xhc3M8Pz5bXSBzdGFDbGFzc2VzID0g
bmV3IENsYXNzPD8+W10geyBNYXRoLmNsYXNzIH07DQogICAgICAgIENsYXNz
PD8+W10gZHluQ2xhc3NlcyA9IG5ldyBDbGFzczw/PltdIHsgSXRlbTEuY2xh
c3MsIEl0ZW0yLmNsYXNzIH07DQogICAgICAgIENsYXNzPD8+W10gZG90Q2xh
c3NlcyA9IG5ldyBDbGFzczw/PlsgMCBdOw0KICAgICAgICBEVk1hcCByZXNv
bHZlciA9IG5ldyBSZXNvbHZlcigpOw0KICAgICAgICBIYXNoTWFwPFN0cmlu
ZyxDbGFzczw/Pj4gY25tYXAgPSBudWxsOw0KDQogICAgICAgIExpYnJhcnkg
bGliID0gbmV3IExpYnJhcnkoIHN0YUNsYXNzZXMsIGR5bkNsYXNzZXMsIGRv
dENsYXNzZXMsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
IHJlc29sdmVyLCBjbm1hcCApOw0KDQogICAgICAgIEl0ZW0xIGl0ZW0xID0g
bmV3IEl0ZW0xKCAyMyApOw0KICAgICAgICBJdGVtMiBpdGVtMiA9IG5ldyBJ
dGVtMiggNSApOw0KICAgICAgICBPYmplY3RbXSBjb250ZXh0ID0gbmV3IE9i
amVjdFtdIHsgaXRlbTEsIGl0ZW0yIH07DQoNCiAgICAgICAgU3RyaW5nW10g
ZXhwclR4dHMgPSBuZXcgU3RyaW5nW10gew0KICAgICAgICAgICAgIjE5KzEi
LA0KICAgICAgICAgICAgInNpbiIsDQogICAgICAgICAgICAic2luKDEpIiwN
CiAgICAgICAgICAgICJnZXREb3VibGVQcm9wZXJ0eShcIiIgKyBQUk9QTkFN
RSArICJcIikiLA0KICAgICAgICAgICAgUFJPUE5BTUUsDQogICAgICAgICAg
ICAiY29zKDEpIiwNCiAgICAgICAgfTsNCiAgICAgICAgZm9yICggU3RyaW5n
IHR4dCA6IGV4cHJUeHRzICkgew0KICAgICAgICAgICAgU3RyaW5nQnVmZmVy
IHNidWYgPSBuZXcgU3RyaW5nQnVmZmVyKCAiICAgIiArIHR4dCApOw0KICAg
ICAgICAgICAgdHJ5IHsNCiAgICAgICAgICAgICAgICBDb21waWxlZEV4cHJl
c3Npb24gZXhwciA9IEV2YWx1YXRvci5jb21waWxlKCB0eHQsIGxpYiApOw0K
ICAgICAgICAgICAgICAgIHNidWYuYXBwZW5kKCAiID0gIiArIGV4cHIuZXZh
bHVhdGUoIGNvbnRleHQgKSApOw0KICAgICAgICAgICAgfQ0KICAgICAgICAg
ICAgY2F0Y2ggKCBUaHJvd2FibGUgZSApIHsNCiAgICAgICAgICAgICAgICBz
YnVmLmFwcGVuZCggIiBGQUlMIFsiICsgZSArICJdIiApOw0KICAgICAgICAg
ICAgfQ0KICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxu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XVhbHMoIG5hbWUgKSA/ICJEb3VibGUiIDogbnVsbDsNCiAg
ICAgICAgfQ0KICAgIH0NCn0NCg==
---561407174-1465009490-1508419644=:7742
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Help-jel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-jel
---561407174-1465009490-1508419644=:7742--