[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Type hierarchy



I have a hierarchy of structure types.  I wish to display the hierarchy
using format-graph-from-root.  Given a structure, is there any way to get the
list of those structures that include it.

For example, given:

(DEFSTRUCT AIR-OBJECT ...)
(DEFSTRUCT (AIRPLANE (:INCUDE AIR-OBJECT)) ...)
(DEFSTRUCT (BLIMP (:INCLUDE AIR-OBJECT)) ...)
(DEFSTRUCT (BIRD (:INCLUDE AIR-OBJECT)) ...)
(DEFSTRUCT (B747 (:INCLUDE AIRPLANE)) ...)

I would like to do: (structure-children 'air-object) -> (AIRPLANE BLIMP BIRD)

I realize I can do:

(defmacro defstruct+ (&rest body)
   (let* ((spec (car body))
	  (name (if (listp spec) (car spec) spec))
	  (parent (and (listp spec)
		       (cadr (find :include spec 
				  :test #'(lambda (x y)
					    (and (listp y) (eq x (car y)))))))))
     (if parent
	 `(progn (push ',name (get ',parent :children))
		 (defstruct ,@body))
	 `(defstruct ,@body))))

However this would mean requiring that users rewrite and/or recompile some
existing code.  Is there any built-in way to go from a type to a subtype?

LSB