This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: Can we prefix with module names? (was Re: Shorthand for Java)
- From: Per Bothner <per at bothner dot com>
- To: Jocelyn Paine <popx at ifs dot org dot uk>
- Cc: Kawa List <kawa at sources dot redhat dot com>
- Date: Tue, 26 Nov 2002 10:43:35 -0800
- Subject: Re: Can we prefix with module names? (was Re: Shorthand for Java)
- References: <Pine.LNX.4.21.0211261817290.22559-100000@pop3.ifs.org.uk>
Jocelyn Paine wrote:
With these, can we now use Kawa module names as prefixes too? Selected at
runtime? So that if modules M1 and M2 both export function f, my code can
pass the name of one of these modules around in a variable V, and then
call V:f?
No, at least not as currently implemented/conceptualized.
First, namespace aliases are in a different namespace:
(define namespace foo "uri")
is equivalent to:
(define-constant MAGIC-foo "uri")
where MAGIC is a reserved internal name.
Secondly, the alias has to be bound to a constant.
That *could* perhaps be relaxed, but I don't know how much
of the implementation would have to be changed.
A cleaner (and much more efficient) solution might be to use interfaces:
Have both modules implement an interface, and then use an alias for
that:
I.java:
public interface I {
public Object f(Object x);
}
M1 (and M2):
(module-implements <I>)
(define (f x) ....)
(define-constant m-instance :: <I>
(select-one-of (make <M1>) (make <M2>)))
(define namespace I "class:I")
(I:f m-instance x)
I make no guarntees whether this works. It
probably *should* ...
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/