(import type-name &key package-name (package-name-prefix $package-name-prefix) extends-package-name type-parameters)


The function import creates a package with symbols for all public methods, properties and fields in the class. Symbol names are derived from the .NET names by inserting an hyphen before every embedded upper case letter and by converting to lower case (sometimes to upper case -- see below). import also registers the package name as a type name with deftype.

If extends-package-name is given, adds extension methods from the CLR type type-name to the existing import package extends-package-name. Otherwise, imports the public fields, properties, events, methods and constructors of the CLR type type-name into the package package-name.

package-name defaults to the concatenation of the string package-name-prefix and the rightmost name part of type-name.

user 1 > (import "System.String")
it: <Package Name="string">
user 2 > (import "Kiezel.StringExtensions" :extends-package-name "string")
it: <Package Name="string">
user 3 > (import "System.Net.WebRequestMethods+Ftp" :package-name :ftp-methods)
it: <Package Name="ftp-methods">
user 4 > (import "System.Collections.Generic.List" :type-parameters '(int))
it: <Package Name="list^1">

Static methods

user 1 > (path:get-extension "readme.txt")
it: ".txt"

Instance methods

user 1 > (string:to-upper "hello")
it: "HELLO"
user 2 > (.to-upper "hello")
it: "HELLO"

The expression .to-upper is discussed in more detail below.

Instance properties

user 1 > (string:length "hello")
it: 5
user 2 > (.length "hello")
it: 5

Literal and static readonly fields

The name is converted to upper case instead of lower case.

user 1 > int32:MAX-VALUE
it: 2147483647

Static properties

user 1 > (encoding:ascii)
it: #<System.Text.ASCIIEncoding>
user 2 > (date-time:now)
it: "2017-04-09 16:55:31"

.members and ?members notation

Instance properties may be accessed by using getter and setter functions but this requires that the class is imported. A convenient alternative is to use accessor expressions. This also applies to methods.

user 1 > .length
it: #<AccessorLambda Name="length" Nullable="False">
user 2 > (.length "hello")
it: 5
user 3 > (map .length '("ada" "ruby" "python"))
it: (3 4 6)

.length is a reader macro that expands to (. "length"), which evaluates to a generic function that retrieves the length property of an object.

It is also possible to chain property accessors:

user 1 > (var a (new :city "leiden"))
it: #s( :city "leiden" )
user 2 > (.city a)
it: "leiden"
user 3 > .city.length
it: #<AccessorLambda Name="city.length" Nullable="False">
user 4 > (.city.length a)
it: 6

Nullable accessors handle null references by returning null instead of throwing a NullReference exception:

user 1 > ?length
it: #<AccessorLambda Name="length" Nullable="True">
user 2 > (?length "hello")
it: 5
user 3 > (?length null)
it: null
user 4 > (var a (new :city "leiden"))
it: #s( :city "leiden" )
user 5 > ?city.length
it: #<AccessorLambda Name="city.length" Nullable="True">
user 6 > (?city.length a)
it: 6
user 7 > (?kity.length a)
it: null

See also

$package-name-prefix reference