improved import syntax

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

improved import syntax

Per Bothner
In an import form, you can now use a classname (ie. a symbol usually
with dots), instead of a list.  I.e.:

(import org.example.Foo)

is equivalent to:

(import (org example Foo))

I don't remember if I announced the import-class form, but it's quite handy:

You can import multiple class from the same package with duplication:

(import (class java.util Map HashMap))

You can also rename it:

(import (class java.lang (StringBuilder StrBuf)))

The above is equivalent to:

(define-alias StrBuf java.lang.StringBuilder)

but with import-class you can import (and optionally rename) many classes
in a compact form.

You can combine the class clause with import's only, except, rename, and prefix clauses,
though only prefix is likely to be useful. For example:

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

is equivalent to

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

--
        --Per Bothner
[hidden email]   http://per.bothner.com/