12 The Built-In Functions
make
[Open Generic Function]
make type #rest supplied-init-args #key #all-keys
Þ instance
<type>
.
<object>
, which must be a general instance of type.
The instance returned is guaranteed to be a general instance of type but not necessarily a direct instance of type. This liberality allows make to be called on an abstract class or other type; it can instantiate and return a direct instance of one of the concrete subtypes of the abstract class or type.
The instance returned may or may not be newly allocated. If a new instance is allocated, make
will call initialize
on the instance before returning it.
Programmers may customize make for particular classes by defining methods specialized by singleton specializers. These methods may obtain the default make behavior, if desired, by calling next-method.
Note that the <class>
method on make
returns a newly allocated direct instance of its first argument.
initialize
on the instance, and then returns the instance. An error is signaled if class is abstract.A complete description of this method and its role in the initialization protocol is given in "Instance Creation and Initialization" on page 63.
(singleton <array>)
#key dimensions fill Þ array [G.F. Method]<array>
. These arguments are described with the <array> class on page 208.(singleton <vector>)
#key size fill Þ simple-object-vector [G.F. Method](singleton <simple-vector>)
#key size fill Þ simple-object-vector [G.F. Method]<simple-object-vector>
. These arguments are described with the <vector>
class on page 210 and with the <simple-vector>
class on page 211.(singleton <list>)
#key size fill Þ list [G.F. Method]<list>
class on page 216.initialize
[Open Generic Function]
initialize instance #key #all-keys
Þ #rest objects
<object>
.
<object>
. The return values are ignored by make
.
By convention, all initialize methods should call next-method very early, to make sure that any initializations from less specific classes are performed first.
The initialize generic function permits all keywords and requires none. It does this because the keyword argument checking is performed by the default method on make.
make
method to call initialize
.slot-initialized?
[Open Generic Function]
slot-initialized? instance getter
Þ boolean
<object>
.
<generic-function>
.
<boolean>
.
slot-initialized?
will signal an error if the getter does not access a slot in the instance.
To support slot-initialized?
for a virtual slot, programmers must define a method for slot-initialized?
which shares a protocol with the getter of the slot.
list
[Function]
list #rest arguments
Þ list
<object>
.
<list>
.
pair
[Function]
pair object1,object2
Þ pair
<object>
.
<object>
.
<pair>
.
pair (1, 2) Þ #(1 . 2) pair (1, #(2, 3, 4, 5)) Þ #(1, 2, 3, 4, 5)Note that while the pair returned by
pair
is freshly allocated, it may be the beginning of a list, portions of which are not freshly allocated.
define variable *preexisting-list* = list(2, 3, 4) define variable *new-list* = pair(1, *preexisting-list*) *new-list* Þ #(1, 2, 3, 4) tail(*new-list*) == *preexisting-list* Þ #t third(*new-list*) := 'x' *new-list* Þ#(1, 2, x, 4) *preexisting-list* Þ
#(2, x, 4)
range
[Function]
range #key from to above below by size
Þ range
<real>
. The default value is 0
.
<real>
.
<real>
.
<real>
.
<real>.
The default value is 0
.
<real>
.
<range>
.
<range>
. The arguments correspond to the initialization arguments of <range>
, described on page 219.
singleton
[Function]
singleton object
Þ singleton
<object>
.
<singleton>
. The singleton for object.
limited
[Function]
limited
class #key
Þ type
<class>
.
<type>
.
(singleton <integer>)
#key min max Þ type [G.F. Method]<integer>
whose instances are integers greater than or equal to min (if min:
is specified) and less than or equal to max (if max:
is specified). If no keyword arguments are specified, the result type is equivalent to <integer>
. Limited integer types are not instantiable.(singleton <collection>)
#key of size Þ type [G.F. Method](singleton
<explicit-key-collection>)
#key of size Þ type [G.F. Method](singleton <mutable-collection>)
#key of size Þ type [G.F. Method](singleton <stretchy-collection>)
#key of size Þ type [G.F. Method](singleton <mutable-explicit-key-collection>)
#key of size Þ type [G.F. Method](singleton <sequence>)
#key of size Þ type [G.F. Method](singleton <mutable-sequence>)
#key of size Þ type [G.F. Method](singleton <table>)
#key of size Þ type [G.F. Method](singleton <object-table>)
#key of size Þ type [G.F. Method]size:
initialization keyword with the same behavior as <table>
.(singleton <array>)
#key of size dimensions Þ type [G.F. Method]dimensions:
and fill:
initialization keywords with the same behavior as <array>
. The default for fill is #f
so if instance?(#f, of)
is not true and the product of the dimensions is nonzero, the fill:
initialization keyword is required because the default would cause a type error.
Instantiating type with a value of dimensions that has one element will return an instance of limited(<simple-vector>, of: of)
.
(singleton <vector>)
#key of size Þ type [G.F. Method]singleton(<simple-vector>)
.
(singleton <simple-vector>)
#key of size Þ type [G.F. Method](singleton <stretchy-vector>)
#key of Þ type [G.F. Method](singleton <deque>)
#key of Þ type [G.F. Method]size:
and fill:
initialization keywords with the same behavior as the collection-class argument. The default for fill is #f
so if instance?(#f, of)
is not true and size is nonzero, the fill:
initialization keyword is required because the default would cause a type error.
All general instances of <simple-vector>
provide a constant time implementation of element
and element-setter
.
(singleton <string>)
#key of size Þ type [G.F. Method]<character>
. This method returns a type that supports size:
and fill:
initialization keywords with the same behavior as <string>
. The default for fill
: is ' '
so if instance?(' ', of)
is not true and size is nonzero, the fill:
initialization keyword is required because the default would cause a type error.
There are no specified subtypes of <character>
, except for unions of singletons, which makes this method rather useless for portable programs. However the method is provided because there might be useful subtypes of <character>
in a particular implementation or in future versions of Dylan.
(singleton <range>)
#key of Þ type [G.F. Method]<real>
. This method returns a type that supports from:
, to:
, below:
, above:
, by:
, and size:
initialization keywords with the same behavior as <range>
. Make of this type signals a <type-error>
if any element of the range is not an instance of of.type-union
[Function]
type-union type1
#rest more-types Þ type
<type>
.
<type>
.
<type>
.
define constant $my-enumerated-type = type-union(singleton(#"one"), singleton(#"two"), singleton(#"three"), singleton(#"four"), singleton(#"five"))
vector
[Function]
vector #rest arguments
Þ vector
<object>
.
<simple-object-vector>
. Its elements are the arguments, in order.
Generated with Harlequin WebMaker