From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 65877 invoked by alias); 20 Sep 2017 13:17:11 -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 65867 invoked by uid 89); 20 Sep 2017 13:17:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=H*RU:aibo.runbox.com, Hx-spam-relays-external:aibo.runbox.com, HX-HELO:aibo.runbox.com, H*Ad:U*per 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 ESMTP; Wed, 20 Sep 2017 13:17:08 +0000 Received: from [10.9.9.212] (helo=mailfront12.runbox.com) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1duesD-0005YD-Ir; Wed, 20 Sep 2017 15:17:05 +0200 Received: from 70-36-239-144.dsl.dynamic.fusionbroadband.com ([70.36.239.144] helo=localhost.localdomain) by mailfront12.runbox.com with esmtpsa (uid:757155 ) (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) id 1duer0-0004IN-Kf; Wed, 20 Sep 2017 15:15:50 +0200 Subject: Re: how to define/put into Environment with type hints? To: Sonny To , Kawa mailing list References: From: Per Bothner Message-ID: <02189604-299a-6c2f-5819-e921244d79fb@bothner.com> Date: Wed, 20 Sep 2017 13:17:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.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: 2017-q3/txt/msg00072.txt.bz2 On 09/20/2017 05:36 AM, Sonny To wrote: > I tried something like this > > env.put(Symbol.valueOf("application"), Symbol.makeUninterned(":: > android.app.Application"),application) > > the result I want is > (define application :: android.app.Application application) > > > if I do, env.put(Symbol.valueOf("application"),application) accessing > application from the repl will > give warnings about missing symbols because its treated as an > java.lang.Object. I don't want to explicitly cast every time i want to > invoke a method or property of application It is common for people new to Kawa to want to play around with environments and/or eval. My general advise to minimize doing either. Scheme is built around lexical binding, and modern Schemes take that further using modules/libraries. Kawa's strength is compilation including compile-time analysis. So if you can possibly avoid using environment objects or eval, do so. There is no way to directly specify types with an environment binding. However, it is possible to do it indirectly: To get the effect of: (define application :: android.app.Application app) you need to evaluate or compile that. The resulting class can be imported (using import/require), and the resulting bindings will have the type specifier. The last piece of the puzzle is loadClass, which loads all the public bindings in a class into an environment. You can use either: kawa.standard.Scheme.loadClass or the lower-level: gnu.language.LoadClass or the still lower-level: gnu.kawa.reflect.ClassMemberLocation.defineAll It might be reasonable to define a helper procedure: (environment-import clas [environment]) This would be a simple wrapper around ClassMemberLocation.defineAll. -- --Per Bothner per@bothner.com http://per.bothner.com/