NextPrevUpTopContentsIndex Complete example of a top-level dspec class

Define a saved-value object which has a name and a value:

(defstruct saved-value

The objects are defined using def-saved-value and stored on the plist of their name:

(defmacro def-saved-value (name value)
  `(dspec:def (def-saved-value ,name)
     (when (record-definition `(def-saved-value ,',name)
       (setf (get ',name 'saved-value)
             (make-saved-value :name ',name
                            :value ,value))

Define a function to retrieve the saved-value object:

(defun find-saved-value (name)
  (get name 'saved-value))

Define a macro to access a saved-value object:

(defmacro saved-value (name)
  `(saved-value-value (find-saved-value ',name)))

Define a dspec class for def-saved-value dspecs:

(dspec:define-dspec-class def-saved-value nil 
  "Defined saved values"
  #'(lambda (name)
      ;; Find any object that def-saved-value recorded
      (not (null (find-saved-value name))))
  #'(lambda (dspec)
      ;; Remove what def-saved-value recorded
      `(remprop ,(dspec:dspec-name dspec) 'saved-value))
  #'(lambda (obj)
      ;; Given a saved-value object, we can reconstruct its dspec
      (and (saved-value-p obj)
           `(def-saved-value ,(saved-value-name obj)))))

For completeness, define a form parser that generates dspecs from forms:

     (:parser dspec:single-form-form-parser)))

Note: this form parser for def-saved-value is not strictly necessary, because the system provides an implicit form parser which recognizes definitions beginning with "def".

LispWorks User Guide - 11 Mar 2008