This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Strange ClassCastException


Hello Everybody:

I've just stumbled on a very (IMHO) strange exception case while running a
trivial programming example in the Kawa REPL (and actually interpreting
it as a file too)

The example is the classical basic/begginer's program to calculate the
area of a circle.

Here is the code just as I typed it in the REPL (and saved it in a file too):

>  #|kawa:1|# (define (circle-area radius) (* java.lang.Math:PI (expt radius 2)))

And I got this result/exception when calling it (or running the file
with kawa -f):

>#|kawa:2|# (circle-area 3)
>java.lang.ClassCastException: java.lang.Double cannot be cast to gnu.math.Numeric
>    at atInteractiveLevel$5.circleArea(stdin:1)
>    at atInteractiveLevel$5.apply1(stdin:1)
>    at gnu.expr.ModuleMethod.apply1(ModuleMethod.java:192)
>    at gnu.expr.ModuleMethod.apply(ModuleMethod.java:163)
>    at gnu.mapping.CallContext.runUntilDone(CallContext.java:234)
>    at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:380)
>    at gnu.expr.ModuleExp.evalModule(ModuleExp.java:217)
>    at kawa.Shell.run(Shell.java:290)
>    at kawa.Shell.run(Shell.java:203)
>    at kawa.Shell.run(Shell.java:184)
>    at kawa.repl.main(repl.java:892)

Now, IMHO the strange thing is that if I eval the same forms outside the
function definition, it all works well and I get the expected result:

>#|kawa:3|# (define radio 3)
>#|kawa:4|# (* java.lang.Math:PI (expt radio 2))
>28.274333882308138

I know that for this basic/trivial example I can workaround it with this:

> (define (circle-area radius)(* java.lang.Math:PI (* radius radius)))

So, my question is: Is this a known bug/feature? Should I submit a bug report?
Is it not-recommended to mix Java and Scheme library functions?

Thanks in advance.

Greetings.
--
Alcides Flores Pineda.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]