file: job.t package: muf status: alpha
As the name suggests, ]defstruct
defines a
structure. A typical sample use is:
Stack: [ 'ship 'x 'y 'mass | ]defstruct
which accomplishes the following:
ship
structure type with three components,
x
, y
and mass
.
ship
becomes the name of this structure type.
ship?
which is true of (only)
instances of this structure type.
]make-ship
which constructs
instances of this type: [ :x 0.5 :y 2.0 :mass 15.0 | ]make-ship --> s
The full syntax follows the CommonLisp standard fairly closely, and (hence?) is fairly intimidating. Using the notation (* x | y *) to indicate a sequence of zero or more x and/or y instances:
'somestructname (* :concName string | :constructor symbol | :copier symbol | :assertion symbol | :predicate symbol | :include symbol | :printFunction cfn | :type symbol | :named symbol | :initialOffset symbol | :export t *) (* 'someslotname (* :init any | :type type | :readOnly tOrNil | :rootMayRead tOrNil | :rootMayWrite tOrNil | :userMayRead tOrNil | :userMayWrite tOrNil | :classMayRead tOrNil | :classMayWrite tOrNil | :worldMayRead tOrNil | :worldMayWrite tOrNil | *) *)
The first group of options apply to the structure proper; The last group of options apply to a particular slot.
Structure options:
:concName string
ship
has slots named mast
and sail
,
]defstruct
will generate slot-reading
functions called ship-mast
and
ship-sail
, and slot-writing functions
called set-ship-mast
and set-ship-sail
.
Specifying :concName "boat-"
will result
in slot-reading functions called boat-mast
and boat-sail
and slot-writing functions
called set-boat-mast
and set-boat-sail
.
:constructor symbol
ship
will
have a constructor function named ]make-ship
.
Specifying :constructor 'xx
will result in
a constructor function named xx
.
:copier symbol
ship
will
have a copier function named copy-ship
.
Specifying :constructor 'cc
will result in
a copier function named cc
.
:assertion symbol
ship
will
have an assertion function named is-a-ship
.
Specifying :assertion 'aa
will result in
an assertion function named aa
.
:predicate symbol
ship
will
have an assertion function named ship?
.
Specifying :predicate 'pp
will result in
a predicate function named dd
.
:include symbol
:include
'somestruct
where somestruct
is a symbol naming
some previously defined structure type will result in
all the slots of somestruct
being included in
the new structure, plus the predicate and slot
functions for the old structure working on the
corresponding slots of the new structure. This is a
simple but useful form of single inheritence.
:printFunction cfn
:type symbol
:named symbol
:initialOffset symbol
:export t
Slot options:
:initval any
]make-foo
command.
:initform nil-or-compiled-fn
:initform
is non-nil,
:initval
is ignored. The :initform
option provides a way to compute initial
values at structure creation time: In particular,
it is useful when you want to create a fresh
object to fill the slot each time a new
structure is created.
command.
:type type
:readOnly tOrNil
:userMayWrite
.
:rootMayRead tOrNil
:rootMayWrite tOrNil
:userMayRead tOrNil
]make-foo
creating the
structure containing the slot.
:userMayWrite tOrNil
]make-foo
creating the
structure containing the slot.
:classMayRead tOrNil
:classMayWrite tOrNil
:worldMayRead tOrNil
:worldMayWrite tOrNil
Go to the first, previous, next, last section, table of contents.