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]

Re: kawa java.util.Random




On 10/30/2015 11:40 AM, Debabrata Pani wrote:
Sorry, the previous mail was sent even before I could complete it.

To continue..

While using java random numbers, I am getting the following warning

#|kawa:43|# (define xx (java.util.Random (java.lang.System:currentTimeMillis)))
#|kawa:44|# xx
java.util.Random@5bfbf16f
#|kawa:45|# (xx:nextInt 10)
/dev/stdin:45:2: warning - no known slot 'nextInt' in java.lang.Object
8
#|kawa:46|# xx

This is observable in both kawa 2.1 and kawa 2.0

Is this a known/expected behavior ?

The reason is the Kawa compiler can't know that you won't later do
something like:
  (set! xx "foo")
so it can't safely infer the type.  (It could in the case where nextInt is
called directly at the top-level, but in the general case if the nextInt
call is inside a function, which might be called at a later time.)

Do any one of:

(define-constant xx (java.util.Random (java.lang.System:currentTimeMillis)))
(! xx (java.util.Random (java.lang.System:currentTimeMillis)))
(define xx ::java.util.Random (java.util.Random (java.lang.System:currentTimeMillis)))

Using '!' is more-or-less equivalent to define-constant.

I'm considering changing Kawa so that the type of xx in the plain-define case
would be 'dynamic' rather than 'java.lang.Object'.  That will suppress the warning.
Alternatively, this could be part of the "interactive mode" improvements
I'm also considering.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


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