This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: kawa java.util.Random
- From: Per Bothner <per at bothner dot com>
- To: kawa at sourceware dot org
- Date: Fri, 30 Oct 2015 11:51:24 -0700
- Subject: Re: kawa java.util.Random
- Authentication-results: sourceware.org; auth=none
- References: <CAKJw4ffgQ5q_Uk-NXCQdJwc=VXi1XKAe=S+8QF9R0BwSYvZnfw at mail dot gmail dot com> <CAKJw4feCLza7s7y_04fzX9Tn0gd=hT2oykNVWO8pjxJg6byvCg at mail dot gmail dot com>
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/