Go to the first, previous, next, last section, table of contents.


]defstruct

Function: ]defstruct { [args] -> }
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:

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
By default, if a structure named 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
By default, a structure named ship will have a constructor function named ]make-ship. Specifying :constructor 'xx will result in a constructor function named xx.
:copier symbol
By default, a structure named ship will have a copier function named copy-ship. Specifying :constructor 'cc will result in a copier function named cc.
:assertion symbol
By default, a structure named ship will have an assertion function named is-a-ship. Specifying :assertion 'aa will result in an assertion function named aa.
:predicate symbol
By default, a structure named ship will have an assertion function named ship?. Specifying :predicate 'pp will result in a predicate function named dd.
:include symbol
By default, a structure contains only the slots explicitly named. Specifying :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
This is specified by the CommonLisp standard but currently ignored.
:type symbol
This is specified by the CommonLisp standard but currently ignored.
:named symbol
This is specified by the CommonLisp standard but currently ignored.
:initialOffset symbol
This is specified by the CommonLisp standard but currently ignored.
:export t
This is not specified by the CommonLisp standard, but I got sick of exporting all the functions generated by a defstruct one at a time by hand: If you set this flag, defstruct will export all symbols it creates.

Slot options:

:initval any
Specifies the default value for the slot if none is specified in the ]make-foo command.
:initform nil-or-compiled-fn
If non-nil, specifies a compiled function of no arguments and one return value which provides the default initial value for the slot. If :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
This is specified by the CommonLisp standard but currently ignored.
:readOnly tOrNil
This is specified by the CommonLisp standard and interpreted as being the negation of :userMayWrite.
:rootMayRead tOrNil
This may be set only by root running OMNIPOTENT, and prevents root from reading the field. Included mainly for completeness.
:rootMayWrite tOrNil
This may be set only by root running OMNIPOTENT, and prevents root from writing the field. May be useful for protecting important data, or indicating that it may be safely cached on remote servers.
:userMayRead tOrNil
Controls whether this slot may be read by the user who did the ]make-foo creating the structure containing the slot.
:userMayWrite tOrNil
Controls whether this slot may be written by the user who did the ]make-foo creating the structure containing the slot.
:classMayRead tOrNil
Controls whether this slot may be read by the owner of the class defining the object.
:classMayWrite tOrNil
Controls whether this slot may be written by the owner of the class defining the object.
:worldMayRead tOrNil
Controls whether this slot may be read by random unprivileged users.
:worldMayWrite tOrNil
Controls whether this slot may be written by random unprivileged users.


Go to the first, previous, next, last section, table of contents.