public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Strange ClassCastException
@ 2014-09-21  5:16 Alcides Flores Pineda
  2014-09-21  7:54 ` Per Bothner
  2014-09-22  6:54 ` Per Bothner
  0 siblings, 2 replies; 4+ messages in thread
From: Alcides Flores Pineda @ 2014-09-21  5:16 UTC (permalink / raw)
  To: Kawa Mailing List

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-09-22 16:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-21  5:16 Strange ClassCastException Alcides Flores Pineda
2014-09-21  7:54 ` Per Bothner
2014-09-22  6:54 ` Per Bothner
2014-09-22 16:22   ` Alcides Flores Pineda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).