18 Programming Language EuLisp, Level-1

This section describes the additions features in EULISP level-1 including the reflective aspects of the object system and how to program the metaobject protocol and some additional control forms.

18.1 Modules

defmodule-1-form:
( defmodule module-name
module-directives
level-1-module-form* )
level-1-module-form:
level-0-module-form
level-1-form
defining-1-form
level-1-form:
level-0-form
special-1-form
form:
level-1-form
special-form:
special-1-form
defining-1-form:
defclass-1-form
defgeneric-1-form
defglobal-form
special-1-form:
generic-lambda-form
method-lambda-form
defmethod-form
??
catch-form
throw-form

18.2 Classes and Objects


18.2.1 defclass
defining operator


18.2.1.1 Syntax

defclass-1-form:
( defclass class-name superclass-list
( slot-1* )
class-option-1* )
superclass-list:
( superclass-name* )
slot-1:
slot
( slot-name slot-option-1* )
slot-option-1:
slot-option
identifier level-1-form
class-option-1
class-optionclass: class-name
identifier level-1-form
Arguments

superclass-list :

A list of symbols naming bindings of classes to be used as the superclasses of the new class (multiple inheritance). This is different from defclass at level-0, where only one superclass may be specified.

slot-1 :

A list of slot specifications (see below), comprising either a slot-name or a list of a slot-name followed by some slot-options. One of the class options (see below) allows the specification of the class of the slot description.

class-option-1 :

A key and a value (see below). One of the class options (<class>) allows the specification of the class of the class being defined.

Remarks

This defining form defines a new class. The resulting class will be bound to class-name. The second argument is a list of superclasses. If this list is empty, the superclass is <object>. The third argument is a list of slots. The remaining arguments are class options. All the slot options and class options are exactly the same way as for defclass (11.3.1).

The slot-option-1s are interpreted as follows:

identifier level-1-form :

The symbol named by identifier and the value of expression are passed to make of the slot description class along with other slot options. The values are evaluated in the lexical and dynamic environment of the defclass. For the language defined slot description classes, no slot keywords are defined which are not specified by particular defclass slot options.

The class-option-1s are interpreted as follows:

class class-name :

The value of this option is the class of the new class. By default, this is <class>. This option must only be specified once for the new class.

identifier level-1-form :

The symbol named by identifier and the value of expression are passed to make on the class of the new class. This list is appended to the end of the list that defclass constructs. The values are evaluated in the lexical and dynamic environment of the defclass. This option is used for metaclasses which need extra information not provided by the standard options.

18.3 Generic Functions


18.3.1 generic-lambda
special operator


18.3.1.1 Syntax

generic-lambda-form:
( generic-lambda gf-lambda-list
level-1-init-option* )
level-1-init-option:
class class-name
method-class class-name
method level-1-method-description
identifier level-1-form
level-0-init-option
level-1-method-description:
( method-init-option*
specialized-lambda-list
body )
method-init-option:
class class-name
identifier level-1-form
Arguments

gf-lambda-list :

As level-0. See section 11.4.5.

level-1-init-option* :

Format as level-0, but with additional options, which are defined below.

Result

A generic function.

Remarks

The syntax of generic-lambda is an extension of the level-0 syntax allowing additional init-options. These allow the specification of the class of the new generic function, which defaults to <generic-function>, the class of all methods, which defaults to <method>, and non-standard options. The latter are evaluated in the lexical and dynamic environment of generic-lambda and passed to make of the generic function as additional initialization arguments. The additional init-options over level-0 are interpreted as follows:

class gf-class :

The class of the new generic function. This must be a subclass of <generic-function>. The default is <generic-function>.

method-class method-class :

The class of all methods to be defined on this generic function. All methods of a generic function must be instances of this class. The method-class must be a subclass of <method> and defaults to <method>.

identifier expression :

The symbol named by identifier and the value of expression are passed to make as keywords. The values are evaluated in the lexical and dynamic environment of the defgeneric. This option is used for classes which need extra information not provided by the standard options.

In addition, method init options can be specified for the individual methods on a generic function. These are interpreted as follows:

class method-class :

The class of the method to be defined. The method class must be a subclass of <method> and is, by default, <method>. The value is passed to make as the first argument. The symbol and the value are not passed as keywords to make.

identifier expression :

The symbol named by identifier and the value of expression are passed to make creating a new method as keywords. The values are evaluated in the lexical and dynamic environment of the generic-lambda. This option is used for classes which need extra information not provided by the standard options.

Examples

In the following example an anonymous version of gf-1 (see defgeneric) is defined. In all other respects the resulting object is the same as gf-1.

(generic-lambda (arg1 (arg2 <class-a>))

  class <another-gf-class>
  class-key-a class-value-a
  class-key-b class-value-b

  method-class <another-method-class-a>

  method (class <another-method-class-b>
          method-class-b-key-a method-class-b-value-a
          ((m1-arg1 <class-b>) (m1-arg2 <class-c>))
          ...)
  method (method-class-a-key-a method-class-a-value-a
          ((m2-arg1 <class-d>) (m2-arg2 <class-e>))
          ...)
  method (class <another-method-class-c>
          method-class-c-key-a method-class-c-value-a
          ((m3-arg1 <class-f>) (m3-arg2 <class-g>))0
          ...)
)

See also

defgeneric.


18.3.2 defgeneric
defining operator


18.3.2.1 Syntax

defgeneric-1-form:
( defgeneric gf-name gf-lambda-list
level-1-init-option )
Arguments

gf name :

As level-0. See section 11.4.5.

gf lambda list :

As level-0. See section 11.4.5.

init option* :

As for generic-lambda, defined above. below.

Remarks

This defining form defines a new generic function. The resulting generic function will be bound to gf-name. The second argument is the formal parameter list. An error is signalled (condition: <non-congruent-lambda-lists> ) if any of the methods defined on this generic function do not have lambda lists congruent to that of the generic function. This applies both to methods defined at the same time as the generic function and to any methods added subsequently by defmethod or add-method. An init-option is a identifier followed by its initial value. The syntax of defgeneric is an extension of the level-0 syntax. The rewrite rules for the defgeneric form are identical to those given in section 11.4.5.2 except that level 1 init option replaces level 0 init option.

Examples

In the following example of the use of defgeneric a generic function named gf-1 is defined. The differences between this function and gf-0 (see 11.4.5) are

  1. The class of the generic function is specified (<another-gf-class>) along with some init-options related to the creation of an instance of that class.
  2. The default class of the methods to be attached to the generic function is specified (<another-method-class-a>) along with an init-option related to the creation of an instance of that class.
  3. In addition, some of the methods to be attached are of a different method class (<another-method-class-b> and <another-method-class-c>) also with method specific init-options. These method classes are subclasses of <another-method-class-a>.
(defgeneric gf-1 (arg1 (arg2 <class-a>))

  class <another-gf-class>
  class-key-a class-value-a
  class-key-b class-value-b

  method-class <another-method-class-a>

  method (class <another-method-class-b>
          method-class-b-key-a method-class-b-value-a
          ((m1-arg1 <class-b>) (m1-arg2 <class-c>))
          ...)
  method (method-class-a-key-a method-class-a-value-a
          ((m2-arg1 <class-d>) (m2-arg2 <class-e>))
          ...)
  method (class <another-method-class-c>
          method-class-c-key-a method-class-c-value-a
          ((m3-arg1 <class-f>) (m3-arg2 <class-g>))
          ...)
)

18.4 Methods


18.4.1 method-lambda
special operator


18.4.1.1 Syntax

method-lambda-form: <function>
( method-lambda
method-init-option*
specialized-lambda-list
body )
Arguments

method init option :

A quoted symbol followed by an expression.

specialized lambda list :

As defined under generic-lambda.

form :

An expression.

Result

This syntax creates and returns an anonymous method with the given lambda list and body. This anonymous method can later be added to a generic function with a congruent lambda list via the generic function add-method. Note that the lambda list can be specialized to specify the method’s domain. The value of the special keywords <class> determines the class to instantiate; the rest of the initlist is passed to make called with this class. The default method class is <method>.

Remarks

The additional method-init-options includes <class>, for specifying the class of the method to be defined, and non-standard options, which are evaluated in the lexical and dynamic environment of method-lambda and passed to initialize of that method.


18.4.2 defmethod
defining operator


18.4.2.1 Syntax

defmethod-1-form:
( defmethod gf-locator
method-init-option*
specialized-lambda-list
body )
Remarks

The defmethod form of level-1 extends that of level-0 to accept method-init-options. This allows for the specification of the method class by means of the <class> init option. This class must be a subclass of the method class of the host generic function. The method class otherwise defaults to that of the host generic function. In all other respects, the behaviour is as that defined in level-0.


18.4.3 method-function-lambda
special operator


Arguments

lambda-list :

A lambda list

form* :

A sequence of forms.

This macro creates and returns an anonymous method function with the given lambda list and body. This anonymous method function can later be added to a method using method-function, or as the function initialization value in a call of make on an instance of <method>. A function of this type is also returned by the method accessor method-function. Only functions created using this macro can be used as method functions. Note that the lambda list must not be specialized; a method’s domain is stored in the method itself.


18.4.4 call-method
function


Arguments

method :

A method.

next-methods :

A list of methods.

arg* :

A sequence of expressions.

This function calls the method method with arguments args. The argument next-methods is a list of methods which are used as the applicable method list for args; it is an error if this list is different from the methods which would be produced by the method lookup function of the generic function of method. If method is not attached to a generic function, its behavior is unspecified. The next-methods are used to determine the next method to call when call-next-method is called within method-fn.


18.4.5 apply-method
function


Arguments

method :

A method.

next-methods :

A list of methods.

form1 …formn-1 :

A sequence of expressions.

formn :

An expression.

This function is identical to call-method except that its last argument is a list whose elements are the other arguments to pass to the method’s method function. The difference is the same as that between normal function application and apply.

18.5 Object Introspection

The only reflective capability which every object possesses is the ability to find its class.


18.5.1 class-of
function


Arguments

object :

An object.

Result

The class of the object.

Remarks

The function class-of can take any LISP object as argument and returns an instance of <class> representing the class of that entity.

18.6 Class Introspection

Standard classes are not redefinable and support single inheritance only. General multiple inheritance can be provided by extensions. Nor is it possible to use a class as a superclass which is not defined at the time of class definition. Again, such forward reference facilities can be provided by extensions. The distinction between metaclasses and non-metaclasses is made explicit by a special class, named <metaclass>, which is the class of all metaclasses. This is different from ObjVlisp, where whether a class is a metaclass depends on the superclass list of the class in question. It is implementation-defined whether <metaclass> itself is specializable or not. This implies that implementations are free to restrict the instantiation tree (excluding the selfinstantiation loop of <metaclass>) to a depth of three levels.

The minimum information associated with a class metaobject is:

  1. The class precedence list, ordered most specific first, beginning with the class itself.
  2. The list of (effective) slot descriptions.
  3. The list of (effective) keywords.

Standard classes support local slots only. Shared slots can be provided by extensions. The minimal information associated with a slot description metaobject is:

  1. The name, which is required to perform inheritance computations.
  2. The default-function, called by default to compute the initial slot value when creating a new instance.
  3. The reader, which is a function to read the corresponding slot value of an instance.
  4. The writer, which is a function to write the corresponding slot of an instance.
  5. The keyword, which is a symbol to access the value which can be supplied to a make call in order to initialize the corresponding slot in a newly created object.

The metaobject classes defined for slot descriptions at level-1 are shown in table 5.


Table 5: Level-1 class hierarchy
A <class>
C <simple-class>
C <function-class>
A <slot>
C <local-slot>
A <function>
A <generic-function>
C <simple-generic-function>
A <method>
C <simple-method>


18.6.1 class-precedence-list
function


Arguments

class :

A class.

Result

A list of classes, starting with class itself, succeeded by the superclasses of class and ending with <object>. This list is equivalent to the result of calling ??.

Remarks

The class precedence list is used to control the inheritance of slots and methods.


18.6.2 <simple-class>
<class>  class


Place holder for <simple-class>.


18.6.3 <function-class>
<class>  class


Place holder for <function-class>.


18.6.4 class-slots
function


Arguments

class :

A class.

Result

A list of slots, one for each of the slots of an instance of class.

Remarks

The slots determine the instance size (number of slots) and the slot access.


18.6.5 class-keywords
function


Arguments

class :

A class.

Result

A list of symbols, which can be used as legal keywords to initialize instances of the class.

Remarks

The keywords correspond to the keywords specified in the keyword slot-option or the keywords class-option when the class and its superclasses were defined.

18.7 Slot Introspection


18.7.1 <slot>
class


The abstract class of all slot descriptions.


18.7.2 <local-slot>
<slot>  class


The class of all local slot descriptions.

Initialization Options

name string :

The name of the slot.

reader function :

The function to access the slot.

writer function :

The function to update the slot.

default-function function :

The function to compute the initial value in the absence of a supplied value.

keyword symbol :

The key to access a supplied initial value.

The default value for all initoptions is ().


18.7.3 slot-name
function


Arguments

slot :

A slot description.

Result

The symbol which was used to name the slot when the class, of which the slot is part, was defined.

Remarks

The slot description name is used to identify a slot description in a class. It has no effect on bindings.


18.7.4 slot-default-function
function


Arguments

slot :

A slot description.

Result

A function of no arguments that is used to compute the initial value of the slot in the absence of a supplied value.


18.7.5 slot-slot-reader
function


Arguments

slot :

A slot description.

Result

A function of one argument that returns the value of the slot in that argument.


18.7.6 slot-slot-writer
function


Arguments

slot :

A slot description.

Result

A function of two arguments that installs the second argument as the value of the slot in the first argument.

18.8 Generic Function Introspection

The default generic dispatch scheme is class-based; that is, methods are class specific. The default argument precedence order is left-to-right.

The minimum information associated with a generic function metaobject is:

  1. The domain, restricting the domain of each added method to a sub-domain.
  2. The method class, restricting each added method to be an instance of that class.
  3. The list of all added methods.
  4. The method look-up function used to collect and sort the applicable methods for a given domain.
  5. The discriminating function used to perform the generic dispatch.


18.8.1 generic-function-domain
function


Arguments

generic-function :

A generic function.

Result

A list of classes.

Remarks

This function returns the domain of a generic function. The domains of all methods attached to a generic function are constrained to be within this domain. In other words, the domain classes of each method must be subclasses of the corresponding generic function domain class. It is an error to modify this list.


18.8.2 generic-function-method-class
function


Arguments

generic-function :

A generic function.

Result

This function returns the class which is the class of all methods of the generic function. Each method attached to a generic function must be an instance of this class. When a method is created using defmethod, method-lambda, or by using the method generic function option in a defgeneric or generic-lambda, it will be an instance of this class by default.


18.8.3 generic-function-methods
function


Arguments

generic-function :

A generic function.

Result

This function returns a list of the methods attached to the generic function. The order of the methods in this list is undefined. It is an error to modify this list.


18.8.4 generic-function-method-lookup-function
function


Arguments

generic-function :

A generic function.

Result

A function.

Remarks

This function returns a function which, when applied to the arguments given to the generic function, returns a sorted list of applicable methods. The order of the methods in this list is determined by compute-method-lookup-function.


18.8.5 generic-function-discriminating-function
function


Arguments

generic-function :

A generic function.

Result

A function.

Remarks

This function returns a function which may be applied to the same arguments as the generic function. This function is called to perform the generic dispatch operation to determine the applicable methods whenever the generic function is called, and call the most specific applicable method function. This function is created by compute-discriminating-function.

18.9 Method Introspection

The minimal information associated with a method metaobject is:

  1. The domain, which is a list of classes.
  2. The function comprising the code of the method.
  3. The generic function to which the method has been added, or () if it is attached to no generic function.

The metaobject classes for generic functions defined at level-1 are shown in table 5.


18.9.1 <method>
class


Place holder for <method>.


18.9.2 <simple-method>
<method>  class


Place holder for ??.


18.9.3 method-domain
function


Arguments

method :

A method.

Result

A list of classes defining the domain of a method.


18.9.4 method-function
function


Arguments

method :

A method.

Result

This function returns a function which implements the method. The returned function which is called when method is called, either by calling the generic function with appropriate arguments, through a call-next-method, or by using call-method. A method metaobject itself cannot be applied or called as a function.


18.9.5 (setter method-function)
setter


Arguments

method :

A method.

function :

A function.

Result

This function sets the function which implements the method.


18.9.6 method-generic-function
function


Arguments

method :

A method.

Result

This function returns the generic function to which method is attached; if method is not attached to a generic function, it returns ().

18.10 Class Initialization


18.10.1 initialize <class>
method


Specialized Arguments

class <class> :

A class.

initlist <list> :

A list of initialization options as follows:

name symbol :

Name of the class being initialized.

direct-superclasses list :

List of direct superclasses.

direct-slots list :

List of direct slot specifications.

direct-keywords list :

List of direct keywords.

Result

The initialized class.

Remarks

The initialization of a class takes place as follows:

  1. Check compatibility of direct superclasses
  2. Perform the logical inheritance computations of:

    1. class precedence list
    2. keywords
    3. slot descriptions
  3. Compute new slot accessors and ensure all (new and inherited) accessors to work correctly on instances of the new class.
  4. Make the results accessible by class readers.

The basic call structure is laid out in figure 6


Table 6: Initialization Call Structure
compatible-superclasses?
cl direct-superclasses boolean
compatible-superclass?
cl superclass boolean
compute-class-precedence-list
cl direct-superclasses (cl*)
compute-inherited-keywords
cl direct-superclasses ((keyword*)*)
compute-keywords
cl direct-keywords inherited-keywords
(keyword*)
compute-inherited-slots
cl direct-superclasses ((sd*)*)
compute-slots
cl slot-specs inherited-sds (sd*)
either
compute-defined-slot
cl slot-spec sd
compute-defined-slot-description-class
cl slot-spec sd-class
or
compute-specialized-slot
cl inherited-sds slot-spec sd
compute-specialized-slot-class
cl inherited-sds slot-spec
sd-class
compute-instance-size
cl effective-sds integer
compute-and-ensure-slot-accessors
cl effective-sds inherited-sds (sd*)
compute-slot-reader
cl sd effective-sds function
compute-slot-writer
cl sd effective-sds function
ensure-slot-reader
cl sd effective-sds reader function
compute-primitive-reader-using-slot
sd cl effective-sds function
compute-primitive-reader-using-class
cl sd effective-sds function
ensure-slot-writer
cl sd effective-sds writer function
compute-primitive-writer-using-slot
sd cl effective-sds function
compute-primitive-writer-using-class
cl sd effective-sds function

Note that compute-keywords is called by the default initialize method with all direct keywords as the second argument: those specified as slot option and those specified as class option.


18.10.2 compute-predicate
generic function


Generic Arguments

class <class> :

A class.

Result

Computes and returns a function of one argument, which is a predicate function for class.


18.10.3 compute-predicate <class>
method


Specialized Arguments

class <class> :

A class.

Result

Computes and returns a function of one argument, which returns t when applied to direct or indirect instances of class and () otherwise.


18.10.4 compute-constructor
generic function


Generic Arguments

class <class> :

A class.

parameters <list> :

The argument list of the function being created.

Result

Computes and returns a constructor function for class.


18.10.5 compute-constructor <class>
method


Specialized Arguments

class <class> :

A class.

parameters <list> :

The argument list of the function being created.

Result

Computes and returns a constructor function, which returns a new instance of class.


18.10.6 allocate
generic function


Generic Arguments

class <class> :

A class.

initlist <list> :

A list of initialization arguments.

Result

An instance of the first argument.

Remarks

Creates an instance of the first argument. Users may define new methods for new metaclasses.


18.10.7 allocate <class>
method


Specialized Arguments

class <class> :

A class.

initlist <list> :

A list of initialization arguments.

Result

An instance of the first argument.

Remarks

The default method creates a new uninitialized instance of the first argument. The initlist is not used by this allocate method.

18.11 Slot Description Initialization


18.11.1 initialize <slot>
method


Specialized Arguments

slot <slot> :

A slot description.

initlist <list> :

A list of initialization options as follows:

name symbol :

The name of the slot.

default-function function :

A function.

keyword symbol :

A symbol.

reader function :

A slot reader function.

writer function :

A slot writer function.

Result

The initialized slot description.

18.12 Generic Function Initialization


18.12.1 initialize <generic-function>
method


Specialized Arguments

gf <generic-function> :

A generic function.

initlist <list> :

A list of initialization options as follows:

name symbol :

The name of the generic function.

domain list :

List of argument classes.

method-class class :

Class of attached methods.

method method-description :

A method to be attached. This option may be specified more than once.

Result

The initialized generic function.

Remarks

This method initializes and returns the generic-function. The specified methods are attached to the generic function by add-method, and its slots are initialized from the information passed in initlist and from the results of calling compute-method-lookup-function and compute-discriminating-function on the generic function. Note that these two functions may not be called during the call to initialize, and that they may be called several times for the generic function.

The basic call structure is: add-method gf method -> gf
compute-method-lookup-function gf domain -> function
compute-discriminating-function gf domain lookup-fn methods -> function

18.13 Method Initialization


18.13.1 initialize <method>
method


Specialized Arguments

method <method> :

A method.

initlist <list> :

A list of initialization options as follows:

domain list :

The list of argument classes.

function fn :

A function, created with method-function-lambda.

generic-function gf :

A generic function.

Result

This method returns the initialized method metaobject method. If the generic-function option is supplied, add-method is called to install the new method in the generic-function.

18.14 Inheritance Protocol


18.14.1 compatible-superclasses?
generic function


Generic Arguments

class <class> :

A class.

direct-superclasses <list> :

A list of potential direct superclasses of class.

Result

Returns t if class is compatible with direct-superclasses, otherwise ().


18.14.2 compatible-superclasses? <class>
method


Specialized Arguments

class <class> :

A class.

direct-superclasses <list> :

A list of potential direct superclasses.

Result

Returns the result of calling compatible-superclass? on class and the first element of the direct-superclasses (single inheritance assumption).


18.14.3 compatible-superclass?
generic function


Generic Arguments

subclass <class> :

A class.

superclass <class> :

A potential direct superclass.

Result

Returns t if subclass is compatible with superclass, otherwise ().


18.14.4 compatible-superclass? <class>
method


Specialized Arguments

subclass <class> :

A class.

superclass <class> :

A potential direct superclass.

Result

Returns t if the class of the first argument is a subclass of the class of the second argument, otherwise ().

If the implementation wishes to restrict the instantiation tree (see introduction to B.4), this method should return () if superclass is <metaclass>.


18.14.5 compatible-superclass? <class>
method


Specialized Arguments

subclass <class> :

A class.

superclass <abstract-class> :

A potential direct superclass.

Result

Always returns t.


18.14.6 compatible-superclass? <abstract-class>
method


Specialized Arguments

subclass <abstract-class> :

A class.

superclass <class> :

A potential direct superclass.

Result

Always returns ().


18.14.7 compatible-superclass? <abstract-class>
method


Specialized Arguments

subclass <abstract-class> :

A class.

superclass <abstract-class> :

A potential direct superclass.

Result

Always returns t.


18.14.8 compute-class-precedence-list
generic function


Generic Arguments

class <class> :

Class being defined.

direct-superclasses <list> :

List of direct superclasses.

Result

Computes and returns a list of classes which represents the linearized inheritance hierarchy of class and the given list of direct superclasses, beginning with class and ending with <object>.


18.14.9 compute-class-precedence-list <list>
method


Specialized Arguments

class <class> :

Class being defined.

direct-superclasses <list> :

List of direct superclasses.

Result

A list of classes.

Remarks

This method can be considered to return a cons of class and the class precedence list of the first element of direct-superclasses (single inheritance assumption). If no direct-superclasses has been supplied, the result is the list of two elements: class and <object>.


18.14.10 compute-slots
generic function


Generic Arguments

class <class> :

Class being defined.

direct-slot-specifications <list> :

A list of direct slot specification.

inherited-slots <list> :

A list of lists of inherited slot descriptions.

Result

Computes and returns the list of effective slot descriptions of class.

See also

compute-inherited-slots.


18.14.11 compute-slots <class>
method


Specialized Arguments

class <class> :

Class being defined.

slot-specs <list> :

List of (direct) slot specifications.

inherited-slot-lists <list> :

A list of lists (in fact one list in single inheritance) of inherited slot descriptions.

Result

A list of effective slot descriptions.

Remarks

The default method computes two sublists:

  1. Calling compute-specialized-slot with the three arguments (i) class, (ii) each inherited-slot as a singleton list, (iii) the slot-spec corresponding (by having the same name) to the slot description, if it exists, otherwise (), giving a list of the specialized slot descriptions.
  2. Calling compute-defined-slot with the three arguments (i) class, (ii) each slot-specification which does not have a corresponding (by having the same name) inherited-slot.

The method returns the concatenation of these two lists as its result. The order of elements in the list is significant. All specialized slot descriptions have the same position as in the effective slot descriptions list of the direct superclass (due to the single inheritance). The slot accessors (computed later) may rely on this assumption minimizing the number of methods to one for all subclasses and minimizing the access time to an indexed reference.

See also

compute-specialized-slot, compute-defined-slot, compute-and-ensure-slot-accessors.


18.14.12 compute-keywords
generic function


Generic Arguments

class <class> :

Class being defined.

keywords <list> :

List of direct keywords.

inherited-keyword-lists <list> :

A list of lists of inherited keywords.

Result

List of symbols.

Remarks

Computes and returns all legal keywords for class.

See also

compute-inherited-keywords.


18.14.13 compute-keywords <class>
method


Specialized Arguments

class <class> :

Class being defined.

keywords <list> :

List of direct keywords.

inherited-keyword-lists <list> :

A list of lists of inherited keywords.

Result

List of symbols.

Remarks

This method appends the second argument with the first element of the third argument (single inheritance assumption), removes duplicates and returns the result. Note that compute-keywords is called by the default initialize method with all direct keywords as the second argument: those specified as slot option and those specified as class option.


18.14.14 compute-inherited-slots
generic function


Generic Arguments

class <class> :

Class being defined.

direct-superclasses <list> :

List of direct superclasses.

Result

List of lists of inherited slot descriptions.

Remarks

Computes and returns a list of lists of effective slot descriptions.

See also

compute-slots.


18.14.15 compute-inherited-slots <class>
method


Specialized Arguments

class <class> :

Class being defined.

direct-superclasses <list> :

List of direct superclasses.

Result

List of lists of inherited slot descriptions.

Remarks

The result of the default method is a list of one element: a list of effective slot descriptions of the first element of the second argument (single inheritance assumption). Its result is used by compute-slots as an argument.


18.14.16 compute-inherited-keywords
generic function


Generic Arguments

class <class> :

Class being defined.

direct-superclasses <list> :

List of direct superclasses.

Result

List of lists of symbols.

Remarks

Computes and returns a list of lists of keywords. Its result is used by compute-keywords as an argument.

See also

compute-keywords.


18.14.17 compute-inherited-keywords <class>
method


Specialized Arguments

class <class> :

Class being defined.

direct-superclasses <list> :

List of direct superclasses.

Result

List of lists of symbols.

Remarks

The result of the default method contains one list of legal keywords of the first element of the second argument (single inheritance assumption).


18.14.18 compute-defined-slot
generic function


Generic Arguments

class <class> :

Class being defined.

slot-spec <list> :

Canonicalized slot specification.

Result

Slot description.

Remarks

Computes and returns a new effective slot description. It is called by compute-slots on each slot specification which has no corresponding inherited slot descriptions.

See also

compute-defined-slot-class.


18.14.19 compute-defined-slot <class>
method


Specialized Arguments

class <class> :

Class being defined.

slot-spec <list> :

Canonicalized slot specification.

Result

Slot description.

Remarks

Computes and returns a new effective slot description. The class of the result is determined by calling compute-defined-slot-class.

See also

compute-defined-slot-class.


18.14.20 compute-defined-slot-class
generic function


Generic Arguments

class <class> :

Class being defined.

slot-spec <list> :

Canonicalized slot specification.

Result

Slot description class.

Remarks

Determines and returns the slot description class corresponding to class and slot-spec .

See also

compute-defined-slot.


18.14.21 compute-defined-slot-class <class>
method


Specialized Arguments

class <class> :

Class being defined.

slot-spec <list> :

Canonicalized slot specification.

Result

The class <local-slot>.

Remarks

This method just returns the class <local-slot>.


18.14.22 compute-specialized-slot
generic function


Generic Arguments

class <class> :

Class being defined.

inherited-slots <list> :

List of inherited slot descriptions (each of the same name as the slot being defined).

slot-spec <list> :

Canonicalized slot specification or ().

Result

Slot description.

Remarks

Computes and returns a new effective slot description. It is called by compute-slots on the class, each list of inherited slots with the same name and with the specialising slot specification list or () if no one is specified with the same name.

See also

compute-specialized-slot-class.


18.14.23 compute-specialized-slot <class>
method


Specialized Arguments

class <class> :

Class being defined.

inherited-slots <list> :

List of inherited slot descriptions.

slot-spec <list> :

Canonicalized sdirect-lot specification or ().

Result

Slot description.

Remarks

Computes and returns a new effective slot description. The class of the result is determined by calling compute-specialized-slot-class.

See also

compute-specialized-slot-class.


18.14.24 compute-specialized-slot-class
generic function


Generic Arguments

class <class> :

Class being defined.

inherited-slots <list> :

List of inherited slot descriptions.

slot-spec <list> :

Canonicalized slot specification or ().

Result

Slot description class.

Remarks

Determines and returns the slot description class corresponding to (i) the class being defined, (ii) the inherited slot descriptions being specialized (iii) the specializing information in slot-spec.

See also

compute-specialized-slot.


18.14.25 compute-specialized-slot-class <class>
method


Specialized Arguments

class <class> :

Class being defined.

inherited-slots <list> :

List of inherited slot descriptions.

slot-spec <list> :

Canonicalized slot specification or ().

Result

The class <local-slot>.

Remarks

This method just returns the class <local-slot>.

18.15 Slot Access Protocol

The slot access protocol is defined via accessors (readers and writers) only. There is no primitive like CLOS’s slot-value. The accessors are generic for standard classes, since they have to work on subclasses and should do the applicability check anyway. The key idea is that the discrimination on slots and classes is performed once at class definition time rather than again and again at slot access time.

Each slot has exactly one reader and one writer as anonymous objects. If a reader/writer slot-option is specified in a class definition, the anonymous reader/writer of that slot is bound to the specified identifier. Thus, if a reader/writer option is specified more than once, the same object is bound to all the identifiers. If the accessor slot-option is specified the anonymous writer will be installed as the setter of the reader. Specialized slots refer to the same objects as those in the superclasses (single inheritance makes that possible). Since the readers/writers are generic, it is possible for a subclass (at the meta-level) to add new methods for inherited slots in order to make the readers/writers applicable on instances of the subclass. A new method might be necessary if the subclasses have a different instance allocation or if the slot positions cannot be kept the same as in the superclass (in multiple inheritance extensions). This can be done during the initialization computations.


18.15.1 compute-and-ensure-slot-accessors
generic function


Generic Arguments

class <class> :

Class being defined.

slots <list> :

List of effective slot descriptions.

inherited-slots <list> :

List of lists of inherited slot descriptions.

Result

List of effective slot descriptions.

Remarks

Computes new accessors or ensures that inherited accessors work correctly for each effective slot description.


18.15.2 compute-and-ensure-slot-accessors <class>
method


Specialized Arguments

class <class> :

Class being defined.

slots <list> :

List of effective slot descriptions.

inherited-slots <list> :

List of lists of inherited slot descriptions.

Result

List of effective slot descriptions.

Remarks

For each slot description in slots the default method checks if it is a new slot description and not an inherited one. If the slot description is new,

  1. calls compute-slot-reader to compute a new slot reader and stores the result in the slot description;
  2. calls compute-slot-writer to compute a new slot writer and stores the result in the slot description;

Otherwise, it assumes that the inherited values remain valid.

Finally, for every slot description (new or inherited) it ensures the reader and writer work correctly on instances of class by means of ensure-slot-reader and ensure-slot-writer.


18.15.3 compute-slot-reader
generic function


Generic Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slot-list <list> :

List of effective slot descriptions.

Result

Function.

Remarks

Computes and returns a new slot reader applicable to instances of class returning the slot value corresponding to slot. The third argument can be used in order to compute the logical slot position.


18.15.4 compute-slot-reader <class>
method


Specialized Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

Result

Generic function.

Remarks

The default method returns a new generic function of one argument without any methods. Its domain is class.


18.15.5 compute-slot-writer
generic function


Generic Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

Result

Function.

Remarks

Computes and returns a new slot writer applicable to instances of class and any value to be stored as the new slot value corresponding to slot. The third argument can be used in order to compute the logical slot position.


18.15.6 compute-slot-writer <class>
method


Specialized Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

Result

Generic function.

Remarks

The default method returns a new generic function of two arguments without any methods. Its domain is class ×<object>.


18.15.7 ensure-slot-reader
generic function


Generic Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

reader <function> :

The slot reader.

Result

Function.

Remarks

Ensures function correctly fetches the value of the slot from instances of class.


18.15.8 ensure-slot-reader <class>
method


Specialized Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

reader <generic-function> :

The slot reader.

Result

Generic function.

Remarks

The default method checks if there is a method in the generic-function. If not, it creates and adds a new one, otherwise it assumes that the existing method works correctly. The domain of the new method is class and the function is

(method-function-lambda ((object class))
(primitive-reader object))

compute-primitive-reader-using-slot is called by ensure-slot-reader method to compute the primitive reader used in the function of the new created reader method.


18.15.9 ensure-slot-writer
generic function


Generic Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

writer <function> :

The slot writer.

Result

Function.

Remarks

Ensures function correctly updates the value of the slot in instances of class.


18.15.10 ensure-slot-writer <class>
method


Specialized Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slot-list <list> :

List of effective slot descriptions.

writer <generic-function> :

The slot writer.

Result

Generic function.

Remarks

The default method checks if there is a method in the generic-function. If not, creates and adds a new one, otherwise it assumes that the existing method works correctly. The domain of the new method is class ×<object> and the function is:

(method-function-lambda ((obj class)
(new-value <object>))
(primitive-writer obj new-value))

compute-primitive-writer-using-slot is called by ensure-slot-writer method to compute the primitive writer used in the function of the new created writer method.


18.15.11 compute-primitive-reader-using-slot
generic function


Generic Arguments

slot <slot> :

Slot description.

class <class> :

Class.

slots <list> :

List of effective slot descriptions.

Result

Function.

Remarks

Computes and returns a function which returns a slot value when applied to an instance of class.


18.15.12 compute-primitive-reader-using-slot <slot>
method


Specialized Arguments

slot <slot> :

Slot description.

class <class> :

Class.

slots <list> :

List of effective slot descriptions.

Result

Function.

Remarks

Calls compute-primitive-reader-using-class. This is the default method.


18.15.13 compute-primitive-reader-using-class
generic function


Generic Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

Result

Function.

Remarks

Computes and returns a function which returns the slot value when applied to an instance of class.


18.15.14 compute-primitive-reader-using-class <class>
method


Specialized Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

Result

Function.

Remarks

The default method returns a function of one argument.


18.15.15 compute-primitive-writer-using-slot
generic function


Generic Arguments

slot <slot> :

Slot description.

class <class> :

Class.

slots <list> :

List of effective slot descriptions.

Result

Function.

Remarks

Computes and returns a function which stores a new slot value when applied on an instance of class and a new value.


18.15.16 compute-primitive-writer-using-slot <slot>
method


Specialized Arguments

slot <slot> :

Slot description.

class <class> :

Class.

slots <list> :

List of effective slot descriptions.

Result

Function.

Remarks

Calls compute-primitive-writer-using-class. This is the default method.


18.15.17 compute-primitive-writer-using-class
generic function


Generic Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

Result

Function.

Remarks

Computes and returns a function which stores the new slot value when applied on an instance of class and new value.


18.15.18 compute-primitive-reader-using-class <class>
method


Specialized Arguments

class <class> :

Class.

slot <slot> :

Slot description.

slots <list> :

List of effective slot descriptions.

Result

Function.

Remarks

The default method returns a function of two arguments.

18.16 Method Lookup and Generic Dispatch


18.16.1 compute-method-lookup-function
generic function


Generic Arguments

gf <generic-function> :

A generic function.

domain <list> :

A list of classes which cover the domain.

Result

A function.

Remarks

Computes and returns a function which will be called at least once for each domain to select and sort the applicable methods by the default dispatch mechanism. New methods may be defined for this function to implement different method lookup strategies. Although only one method lookup function generating method is provided by the system, each generic function has its own specific lookup function which may vary from generic function to generic function.


18.16.2 compute-method-lookup-function <generic-function>
method


Specialized Arguments

gf <generic-function> :

A generic function.

domain <list> :

A list of classes which cover the domain.

Result

A function.

Remarks

Computes and returns a function which will be called at least once for each domain to select and sort the applicable methods by the default dispatch mechanism. It is not defined, whether each generic function may have its own lookup function.


18.16.3 compute-discriminating-function
generic function


Generic Arguments

gf <generic-function> :

A generic function.

domain <list> :

A list of classes which span the domain.

lookup-fn <function> :

The method lookup function.

methods <list> :

A list of methods attached to the generic-function.

Result

A function.

Remarks

This generic function computes and returns a function which is called whenever the generic function is called. The returned function controls the generic dispatch. Users may define methods on this function for new generic function classes to implement non-default dispatch strategies.


18.16.4 compute-discriminating-function <generic-function>
method


Specialized Arguments

gf <generic-function> :

A generic function.

domain <list> :

A list of classes which span the domain.

lookup-fn <function> :

The method lookup function.

methods <list> :

A list of methods attached to the generic-function.

Result

A function.

Remarks

This method computes and returns a function which is called whenever the generic function is called. This default method implements the standard dispatch strategy: The generic function’s methods are sorted using the function returned by compute-method-lookup-function, and the first is called as if by call-method, passing the others as the list of next methods. Note that call-method need not be directly called.


18.16.5 add-method
generic function


Generic Arguments

gf <generic-function> :

A generic function.

method <method> :

A method to be attached to the generic function.

Result

This generic function adds method to the generic function gf. This method will then be taken into account when gf is called with appropriate arguments. It returns the generic function gf. New methods may be defined on this generic function for new generic function and method classes.

Remarks

In contrast to CLOS, add-method does not remove a method with the same domain as the method being added. Instead, a noncontinuable error is signalled.


18.16.6 add-method <generic-function>
method


Specialized Arguments

gf <generic-function> :

A generic function.

method <method> :

A method to be attached.

Result

The generic function.

Remarks

This method checks that the domain classes of the method are subclasses of those of the generic function, and that the method is an instance of the generic function’s method class. If not, signals an error (condition: ?? ). It also checks if there is a method with the same domain already attached to the generic function. If so, a noncontinuable error is signaled (condition: <method-domain-clash> ). If no error occurs, the method is added to the generic function. Depending on particular optimizations of the generic dispatch, adding a method may cause some updating computations, e.g. by calling compute-method-lookup-function and compute-discriminating-function.

18.17 Low Level Allocation Primitives

This module provides primitives which are necessary to implement new allocation methods portably. However, they should be defined in such a way that objects cannot be destroyed unintentionally. In consequence it is an error to use primitive-class-of, primitive-ref and their setters on objects not created by primitive-allocate.


18.17.1 primitive-allocate
function


Arguments

class :

A class.

size :

An integer.

Result

An instance of the first argument.

Remarks

This function returns a new instance of the first argument which has a vector-like structure of length size. The components of the new instance can be accessed using primitive-ref and updated using primitive-ref. It is intended to be used in new allocate methods defined for new metaclasses.


18.17.2 primitive-class-of
function


Arguments

object :

An object created by primitive-allocate.

Result

A class.

Remarks

This function returns the class of an object. It is similar to class-of, which has a defined behaviour on any object. It is an error to use primitive-class-of on objects which were not created by primitive-allocate.


18.17.3 (setter primitive-class-of)
setter


Arguments

object :

An object created by primitive-allocate.

class :

A class.

Result

The class.

Remarks

This function supports portable implementations of

  1. dynamic classification like change-class in CLOS.
  2. automatic instance updating of redefined classes.


18.17.4 primitive-ref
function


Arguments

object :

An object created by primitive-allocate.

index :

The index of a component.

Result

An object.

Remarks

Returns the value of the objects component corresponding to the supplied index. It is an error if index is outside the index range of object. This function is intended to be used when defining new kinds of accessors for new metaclasses.


18.17.5 (setter primitive-ref)
setter


Arguments

object :

An object created by primitive-allocate.

index :

The index of a component.

value :

The new value, which can be any object.

Result

The new value.

Remarks

Stores and returns the new value as the objects component corresponding to the supplied index. It is an error if index is outside the index range of object. This function is intended to be used when defining new kinds of accessors for new metaclasses.

18.18 Dynamic Binding


18.18.1 dynamic
special operator


18.18.1.1 Syntax

dynamic-form: <object>
( dynamic identifier )
Arguments

identifier :

A symbol naming a dynamic binding.

Result

The value of closest dynamic binding of identifier is returned. If no visible binding exists, an error is signaled (condition: <unbound-dynamic-variable> ).


18.18.2 dynamic-setq
special operator


18.18.2.1 Syntax

dynamic-setq-form: <object>
( dynamic-setq identifier form )
Arguments

identifier :

A symbol naming a dynamic binding to be updated.

form :

An expression whose value will be stored in the dynamic binding of identifier.

Result

The value of form.

Remarks

The form is evaluated and the result is stored in the closest dynamic binding of identifier. If no visible binding exists, an error is signalled (condition: <unbound-dynamic-variable> ).


18.18.3 <unbound-dynamic-variable>
<general-condition>  condition


Initialization Options

symbol symbol :

A symbol naming the (unbound) dynamic variable.

Remarks

Signalled by dynamic or dynamic-setq if the given dynamic variable has no visible dynamic binding.


18.18.4 dynamic-let
special operator


18.18.4.1 Syntax

dynamic-let-form: <object>
( dynamic-let binding*
body )
Arguments

binding* :

A list of binding specifiers.

body :

A sequence of forms.

Result

The sequence of forms is evaluated in order, returning the value of the last one as the result of the dynamic-let form.

Remarks

A binding specifier is either an identifier or a two element list of an identifier and an initializing form. All the initializing forms are evaluated from left to right in the current environment and the new bindings for the symbols named by the identifiers are created in the dynamic environment to hold the results. These bindings have dynamic scope and dynamic extent . Each form in body is evaluated in order in the environment extended by the above bindings. The result of evaluating the last form in body is returned as the result of dynamic-let.


18.18.5 defglobal
defining operator


18.18.5.1 Syntax

defglobal-form: <object>
( defglobal identifier level-1-form )
Arguments

identifier :

A symbol naming a top dynamic binding containing the value of form.

form :

The form whose value will be stored in the top dynamic binding of identifier.

Remarks

The value of form is stored as the top dynamic value of the symbol named by identifier . The binding created by defglobal is mutable. An error is signaled (condition: <dynamic-multiply-defined> ), on processing this form more than once for the same identifier.

NOTE 1 The problems engendered by cross-module reference necessitated by a single top-dynamic environment are leading to a reconsideration of the defined model. Another unpleasant aspect of the current model is that it is not clear how to address the issue of importing (or hiding) dynamic variables—they are in every sense global, which conflicts with the principle of module abstraction. A model, in which a separate top-dynamic environment is associated with each module is under consideration for a later version of the definition.


18.18.6 <dynamic-multiply-defined>
<general-condition>  condition


Initialization Options

symbol symbol :

A symbol naming the dynamic variable which has already been defined.

Remarks

Signalled by defglobal if the named dynamic variable already exists.

18.19 Exit Extensions


18.19.1 catch
special operator


18.19.1.1 Syntax

catch-form: <object>
( catch tag body )
tag:
symbol
Remarks

The catch operator is similar to block, except that the scope of the name (tag) of the exit function is dynamic. The catch tag must be a symbol because it is used as a dynamic variable to create a dynamically scoped binding of tag to the continuation of the catch form. The continuation can be invoked anywhere within the dynamic extent of the catch form by using throw. The forms are evaluated in sequence and the value of the last one is returned as the value of the catch form.

18.19.1.2 Rewrite Rules
(catch) Is an error
(catch tag) (progn tag ())
(catch tag body)
(let/cc tmp
(dynamic-let ((tag tmp))
body))
Exiting from a catch, by whatever means, causes the restoration of the lexical environment and dynamic environment that existed before the catch was entered. The above rewrite for catch, causes the variable tmp to be shadowed. This is an artifact of the above presentation only and a conforming processor must not shadow any variables that could occur in the body of catch in this way.
See also

throw.


18.19.2 throw
special operator


18.19.2.1 Syntax

throw-form: <object>
( throw tag body )
Remarks

In throw, the tag names the continuation of the catch from which to return. throw is the invocation of the continuation of the catch named tag. The body is evaluated and the value are returned as the value of the catch named by tag. The tag is a symbol because it used to access the current dynamic binding of the symbol, which is where the continuation is bound.

18.19.2.2 Rewrite Rules
(throw) Is an error
(throw tag) ((dynamic tag) ())
(throw tag form)((dynamic tag) form)
See also

catch.

18.20 Summary of Level-1 Defining, Special and Function-call Forms

This section gives the syntax of all level-1 forms:

Any productions undefined here appear elsewhere in the definition, specifically: the syntax of most expressions and definitions is given in the section defining level-0.

18.20.1 Syntax of Level-1 modules
defmodule-1-form:
( defmodule module-name
module-directives
level-1-module-form* )
level-1-module-form:
level-0-module-form
level-1-form
defining-1-form
level-1-form:
level-0-form
special-1-form
form:
level-1-form
special-form:
special-1-form
defining-1-form:
defclass-1-form
defgeneric-1-form
defglobal-form
special-1-form:
generic-lambda-form
method-lambda-form
defmethod-form
??
catch-form
throw-form

18.20.2 Syntax of Level-1 defining forms
defclass-1-form:
( defclass class-name superclass-list
( slot-1* )
class-option-1* )
superclass-list:
( superclass-name* )
slot-1:
slot
( slot-name slot-option-1* )
slot-option-1:
slot-option
identifier level-1-form
class-option-1
class-optionclass: class-name
identifier level-1-form
defgeneric-1-form:
( defgeneric gf-name gf-lambda-list
level-1-init-option )
defmethod-1-form:
( defmethod gf-locator
method-init-option*
specialized-lambda-list
body )
defglobal-form: <object>
( defglobal identifier level-1-form )

18.20.3 Syntax of Level-1 special forms
dynamic-form: <object>
( dynamic identifier )
dynamic-setq-form: <object>
( dynamic-setq identifier form )
dynamic-let-form: <object>
( dynamic-let binding*
body )
generic-lambda-form:
( generic-lambda gf-lambda-list
level-1-init-option* )
level-1-init-option:
class class-name
method-class class-name
method level-1-method-description
identifier level-1-form
level-0-init-option
level-1-method-description:
( method-init-option*
specialized-lambda-list
body )
method-init-option:
class class-name
identifier level-1-form
method-lambda-form: <function>
( method-lambda
method-init-option*
specialized-lambda-list
body )
catch-form: <object>
( catch tag body )
tag:
symbol
throw-form: <object>
( throw tag body )