* improvements to import form
@ 2015-04-15 6:08 Per Bothner
2015-04-15 6:42 ` mikel evins
0 siblings, 1 reply; 2+ messages in thread
From: Per Bothner @ 2015-04-15 6:08 UTC (permalink / raw)
To: Kawa mailing list
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: improvements to import form
2015-04-15 6:08 improvements to import form Per Bothner
@ 2015-04-15 6:42 ` mikel evins
0 siblings, 0 replies; 2+ messages in thread
From: mikel evins @ 2015-04-15 6:42 UTC (permalink / raw)
To: Per Bothner; +Cc: mikel evins, Kawa mailing list
> On Apr 15, 2015, at 1:07 AM, Per Bothner <per@bothner.com> wrote:
>
> 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.
Thanks, Per. This is very nice for my uses and will eliminate some macrology I've been using.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-04-15 6:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-15 6:08 improvements to import form Per Bothner
2015-04-15 6:42 ` mikel evins
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).