Top

5.1(clos user) -CLOS user APIs

Library (clos user)
User level CLOS API collection library.

Macro define-class name supers slots . options
Name must be symbol or identifier.

Supers must be list of class.

Slots must be following structure:

slots ::= (slot ...)
slot  ::= (slot-name specifiers*)
specifiers ::= :init-keyword keyword 
		 | :init-value value
                 | :init-form form
                 | :reader reader-function
                 | :writer writer-function

Defines a new class.

Slot specifiers:

:init-keyword
This keyword specifies initialisation keyword argument used by the make procedure. Following code describes how to use:
(make <a-class> :slot-a 'slot-a-value)
<a-class> has a slot which slot definition contains the keyword :init-keyword with the keyword :slot-a. The code initialises an instance of the slot with given value slot-a-value.
:init-value
This keyword specifies an initial value of target slot.
:init-form
Similar with :init-keyword but this keyword takes expression which will be evaluated at initialiation time.
:reader
This keyword creates a procedure takes 1 argument an instance of the class to access the slot, so users can read the slot without using slot-ref procedure.
:writer
This keyword creates a procedure takes 2 argument an instance of the class and object to set the slot value with given object, so users can set the slot without using slot-set! procedure.

opttions can specify the metaclass of this class with keyword :metaclass.

NOTE: Current implementation does not support :allocation keyword by default. If you need it, see (sagittarius mop allocation).

Macro define-generic name
Name must be symbol.

Creates a new generic function.

Macro define-method name specifiers body ...
Name must be symbol.

Specifiers must be following structure:

specifiers ::= (spec ... rest)
spec ::= (argument-name class) | (argument-name)
rest ::= '() | symbol

Adds defined method to name generic. If the generic does not exist, this will create a new generic function implicitly.

Function slot-ref obj slot-name
Returns the slot value specified slot-name.

Function slot-set! obj slot-name value
Sets the slot value value with specified slot-name.

Function slot-bound? obj slot-name
Returns #t if the slot value specified slot-name is bounded, otherwise #f.

Generic make class args ...
Creates a new instance of class

Function is-a? object class
Returns #t if object is an instance of class, otherwise #f.

Function subtype? class1 class2
Returns #t if class1 is a subclass of class2, otherwise #f.

Function slot-ref-using-accessor object accessor
This procedure is for MOP.

Returns the slot value got by accessor.

Function slot-set-using-accessor! object accessor value
This procedure is for MOP.

Sets the slot value value to object using accessor.

Function slot-ref-using-class class object slot-name
This procedure is for MOP.

Returns the slot value according to the given class.

It is an error if the given slot-name doesn't exist in the class.

Function slot-set-using-accessor! class object slot-name value
This procedure is for MOP.

Sets the slot value value to object accoring to the given class.

It is an error if the given slot-name doesn't exist in the class.

Function slot-bound-using-class? class object slot-name
This procedure is for MOP.

Returns #t if the slot is bounded according to the given class, otherwise #f.

It is an error if the given slot-name doesn't exist in the class.

Generic write-object object (out <port>)
This method will be called when writing the given object.

Defines how user defined class should be written.

Generic object-equal? object1 object2
This method will be called when equal? is called.

Defines how user defined class should be compared.

Top