This is the mail archive of the kawa@sources.redhat.com 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: Can we prefix with module names? (was Re: Shorthand for Java)


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/


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