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

Static methods

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

Instance methods

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

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

Instance properties

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

Literal and static readonly fields

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

user > int32:MAX-VALUE
it: 2147483647

Static properties

user > (encoding:ascii)
it: #<System.Text.ASCIIEncoding>
user > (date-time:now)
it: "2017-10-09 17:29:58"

.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 > .length
it: #<AccessorLambda Name="length" Nullable="False">
user > (.length "hello")
it: 5
user > (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 > (var a (new :city "leiden"))
it: a
user > (.city a)
it: "leiden"
user > .city.length
it: #<AccessorLambda Name="city.length" Nullable="False">
user > (.city.length a)
it: 6

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

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

See also

$package-name-prefix reference