From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122660 invoked by alias); 30 Oct 2015 18:51:45 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 122648 invoked by uid 89); 30 Oct 2015 18:51:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 30 Oct 2015 18:51:43 +0000 Received: from [10.9.9.209] (helo=mailfront04.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1ZsEm3-0007jo-Hy for kawa@sourceware.org; Fri, 30 Oct 2015 19:51:39 +0100 Received: from 70-36-239-58.dsl.dynamic.fusionbroadband.com ([70.36.239.58] helo=toshie.bothner.com) by mailfront04.runbox.com with esmtpsa (uid:757155 ) (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) id 1ZsEls-0001mX-35 for kawa@sourceware.org; Fri, 30 Oct 2015 19:51:28 +0100 Subject: Re: kawa java.util.Random To: kawa@sourceware.org References: From: Per Bothner Message-ID: <5633BC2C.5000605@bothner.com> Date: Fri, 30 Oct 2015 18:51:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-q4/txt/msg00033.txt.bz2 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/