All Manuals > LispWorks® User Guide and Reference Manual > 7 Dspecs: Tools for Handling Definitions

7.4 Types of relations between definitions

7.4.1 Functionally equivalent definers

When one definition form simply macroexpands into another, or otherwise has an identical effect as far as the dspec system is concerned, the dspec system should consider them variant forms of the same class.

Use define-dspec-alias to convert one definer to the other during canonicalization. A pre-defined example of this in LispWorks is defparameter and defvar. These cannot be distinguished (other than in the source code), so defparameter has been defined as a dspec alias for defvar. However, defvar and defconstant define distinct kinds of variable, since we can easily tell which type of definition is in effect by calling the function constantp. To define their dspecs, LispWorks creates a dspec class called variable and uses it as the superspace argument when defining the defvar and defconstant dspec classes.

As an explicit example, suppose you have a defining macro:

(defmacro parameterdef  (value name)
  `(defparameter ,name ,value))

then the following:

(dspec:define-dspec-alias parameterdef (value name)
  `(defparameter ,name))

would be a suitable appropriate alias definition. This define-dspec-alias form defines the dspec.

define-dspec-alias is like deftype for dspecs, so it could be used to describe complicated conversions, as long as it can be done purely statically and totally in terms of existing dspecs. However, nothing more complicated than defparameter has been found necessary.

7.4.2 Grouping subdefinitions together

Some definition forms are macros that expand into a group of other definitions, for example defstruct. When the form is associated with a dspec class, the subdefinitions can be automatically recorded as being subforms of the new definition, by use of the def macro.

This means that the dspec system knows that the subdefinitions were inside the main definition (indeed, inside this particular form). Therefore:

Note: to make source location work you will also need a define-form-parser definition for the macro that expands into the def.

Note: def defines a relation between two particular definitions, for example (defstruct foo) and (defun make-foo), not between the two dspec classes.

7.4.3 Distributed definitions

Some definitions are additions to another class of definition, for example methods are additions to generic functions. We call these distributed definitions, consisting of "parts" and "the aggregate".

The primary name of a part gives the primary name of the aggregate it is a part of, and the qualifiers distinguish it from the other parts of the same aggregate. Only a part dspec may have qualifiers.

LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:19