On this page:
make-hierarchy
hierarchy?
global-hierarchy
exn: fail: hierarchy
parents
ancestors
descendants
derived?
derive
Version: 4.1.3.9

1 Ad-Hoc Hierarchies of Values

 (require (planet "hierarchy.ss" ("murphy" "multimethod.plt" 1 0)))

This module provides support for ad-hoc hierarchies of values that can be used by multimethods.

(make-hierarchy)  hierarchy?

Creates a new value hierarchy.

(hierarchy? v)  boolean?
  v : any/c

Determines whether the given value is a hierarchy.

global-hierarchy : (parameter/c hierarchy?)

The global default value hierarchy.

(struct (exn:fail:hierarchy exn:fail) (child parent)
  #:transparent)
  child : any/c
  parent : any/c

Exception type raised when an illegal modification to a hierarchy is attempted.

(parents [h] v)  hash?
  h : hierarchy? = (global-hierarchy)
  v : any/c

Retrieves all direct parents of v registered in h.

Returns a hash table mapping all the parents to #t.

(ancestors [h] v)  hash?
  h : hierarchy? = (global-hierarchy)
  v : any/c

A transitive version of parents. Retrieves all ancestors of v registered in h or in the global default hierarchy, if the single argument form is used.

Returns a hash table mapping all the ancestors to #t.

(descendants [h] v)  hash?
  h : hierarchy? = (global-hierarchy)
  v : any/c

The counterpart of ancestors. Retrieves all descendants of v registered in h or in the global default hierarchy, if the single argument form is used.

Returns a hash table mapping all the ancestors to #t.

(derived? [h] child parent)  boolean?
  h : hierarchy? = (global-hierarchy)
  child : any/c
  parent : any/c

Checks whether child is a descendant of parent using the scheme object system and the ad-hoc hierarchy h or the global default hierarchy, if the two argument form is used.

This procedure first converts child and / or parent into interfaces using class->interface, if they are classes. Then it returns #t iff any of the following conditions, which are checked in order, is fulfilled:

(derive child parent)  void?
  child : any/c
  parent : (not/c (or/c class? interface?))
(derive h child parent)  hierarchy?
  h : hierarchy?
  child : any/c
  parent : (not/c (or/c class? interface?))

Registers a direct parent of a child in a value hierarchy. Updates the descendants and ancestors relations accordingly.

Before the new relation is registered, the child is converted to an interface using class->interface, if it is a class. The parent may not be a class or interface. Inheritance from classes or interfaces must be done through the object system.

If the child already derives from the parent or if the new inheritance relation would create a cycle, this procedure signals an error.

If the two argument form of the procedure is used, the new modified type hierarchy is based on the global hierarchy and replaces it. In the three argument form, the new hierarchy is returned. The original hierarchy object is never modified by this operation.