This is the mail archive of the kawa@sourceware.org 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]

improvements to import form


Using define-alias to abbreviate a classname is a bit verbose:

(define-alias StringBuffer java.lang.StringBuffer)

I checked in a new variant of import which should be more convenient:

(import (class java.lang StringBuffer))

The syntax is (import (class PREFIX NAME1 NAME2 ... NAMEN)).
This is roughly equivalent to:
  (define-alias NAME1 PREFIX.NAME1)
  (define-alias NAME2 PREFIX.NAME2)
  ...
  (define-alias NAMEN PREFIX.NAMEN)

Strictly speaking, it's more like define-private-alias, since the new
names are (by default) not exported.

You can do renaming; you can have multiple class-clauses in an import;
you can combine it with other import clauses (most usually prefix).

As an example, kawa/lib/numbers.scm now contains:

(import (class java.lang Double)
        (class gnu.math IntNum Numeric RatNum RealNum (Quaternion quaternion))
        (class gnu.kawa.lispexpr LangObjType))

Note how gnu.math.Quaternion is renamed to quaternion.

An example showing the use with prefix:

(import (prefix (class java.lang Long Short) jl-))

This is equivalent to:

(import (class java.lang (Long jl-Long) (Short jl-Short)))

which is equivalent to:

(define-private-alias jl-Short java.lang.Short)
(define-private-alias jl-Long java.lang.Long)

In a related change, I extended the only clause of the import form to
allow reaming, having having to write an explicit rename clause.  For example:

(import (only (kawa example) A (B1 B2) C (D1 D2)))

is equivalent to:

(import (rename (only (kawa example) A B1 C D1)
                (B1 B2) (D1 D2)))

The names A, B1, C, and D1 must existing in the library (kawa example).
The bindings are accessible using the names A, B2, C, and D2.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


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