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


]defclass

Function: ]defclass { [args] -> }
file: job.t
package: muf
status: alpha

As the name suggests, ]defclass defines a class. A typical sample use is:

Stack:
[ 'ship   'x 'y 'mass | ]defclass

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:

'aClassName
(* :isA          'anotherClassName 
|  :is            'anotherClassName 
|  :has           'anotherClassName 
|  :hasA         'anotherClassName 
|  :metaclass     'metaclassName
|  :documentation "some text"
|  :fertile       tOrNil
|  :abstract      tOrNil
|  :export        tOrNil
*)
(* :slot :my-slot
  (*
  |   :initval  any
  |   :initform cfn
  |   :initarg  'aName
  |   :type type
  |   :reader   'readerFnName
  |   :writer   'writerFnName
  |   :accessor 'accessorFnName
  |   :allocation :class
  |   :allocation :instance
  |   :documentation "some text"
  |   :rootMayRead    tOrNil
  |   :rootMayWrite   tOrNil
  |   :userMayRead    tOrNil
  |   :userMayWrite   tOrNil
  |   :classMayRead   tOrNil
  |   :classMayWrite  tOrNil
  |   :worldMayRead   tOrNil
  |   :worldMayWrite  tOrNil
  |   :prot "rw----"
  *)
*)

The first group of options apply to the class proper; The last group of options apply to a particular slot.

Structure options:

:metaclass symbol
MOS allows you to extend it by defining and using new metaclasses. Muq does not currently support this.
:isA symbol
You need one entry like this for each superclass of the new class. Muq current requires that the superclass have already been defined, although CLOS only requires that it be defined before an instance of the new class is created. (The synonyms :is, :has and :hasA are also supported, simply because they sometimes let code read more naturally.)
:documentation string
Human-readable documentation describing the class.
:initarg symbol value
A symbol name, and the corresponding initial value for it. This allows you to specify an initial value for a slot which you are not declaring. (Presumably you are either inheriting it, or expect a subclass of this class to declare it.)

The next section declares those slots which are not inherited, together with optional slot options declaring individual properties for each slot.

Slot options:

:initform any
Specifies a default initial value for the slot in a newly created instance of the class.
:initarg 'symbol
Specifies a name by which the slot may be idenfified in initializeInstance. MOS allows multiple :initarg values per slot, Muq currently allows only one.
:type type
This is specified by the CommonLisp standard but currently ignored.
:documentation "some text"
This allows a human-readable description string to be associated with the slot.
:allocation { :class | :instance }
Normally, a slot is allocated space in each instance of the class. Specifying an :allocation of :class results in the slot instead being allocated in the class itself, containing a single value shared between all instances.
:reader 'symbol
Specifies the name for a generic function which will read the value of this slot from an instance of this class. MOS allows multiple :reader options per slot, Muq currently allows only one.
:writer 'symbol
Specifies the name for a generic function which will set the value of this slot in an instance of this class. MOS allows multiple :writer options per slot, Muq currently allows only one.
:accessor 'xxx
Same as reader, except that a writer named setf-xxx will also be defined. MOS allows multiple :accessor options per slot, Muq currently allows only one.
: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.
:prot "rw----"
An abbreviation for the preceding six properties: The six characters in the value string control user, class and world read/write privileges in the obvious fashion.


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