import
builtin-function
(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.
make-html > (import "System.String")
it: <Package Name="string">
make-html > (import "Kiezel.StringExtensions" :extends-package-name "string")
it: <Package Name="string">
make-html > (import "System.Net.WebRequestMethods+Ftp" :package-name :ftp-methods)
it: <Package Name="ftp-methods">
make-html > (import "System.Collections.Generic.List" :type-parameters '(int))
it: <Package Name="list^1">
make-html > (path:get-extension "readme.txt")
it: ".txt"
make-html > (string:to-upper "hello")
it: "HELLO"
make-html > (.to-upper "hello")
it: "HELLO"
The expression .to-upper is discussed in more detail below.
make-html > (string:length "hello")
it: 5
make-html > (.length "hello")
it: 5
The name is converted to upper case instead of lower case.
make-html > int32:MAX-VALUE
it: 2147483647
make-html > (encoding:ascii)
it: #<System.Text.ASCIIEncoding+ASCIIEncodingSealed>
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.
make-html > .length
it: #<AccessorLambda Name="length" Nullable="False">
make-html > (.length "hello")
it: 5
make-html > (map .length '("ada" "ruby" "python"))
it: (3 4 6)
make-html > (def obj (new :city "leiden"))
it: obj
make-html > (.city obj)
it: "leiden"
make-html > (.country obj)
it: null
.length is a reader macro that expands to (. "length"), which
evaluates to a generic function that retrieves the length property of an
object.
Nullable accessors handle null references by returning null instead of
throwing a NullReference exception:
make-html > ?length
it: #<AccessorLambda Name="length" Nullable="True">
make-html > (?length "hello")
it: 5
make-html > (?length null)
it: null