1 Ad-Hoc Hierarchies of Values
(require (planet "hierarchy.ss" ("murphy" "multimethod.plt" 2 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.
| ||||||||||
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. This is the counterpart of children.
Returns a hash table mapping all the parents to #t.
(children [h] v) → hash? |
h : hierarchy? = (global-hierarchy) |
v : any/c |
Retrieves all direct children of v registered in h. This is the counterpart of parents.
Returns a hash table mapping all the children 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. This is the counterpart of descendants.
Returns a hash table mapping all the ancestors to #t.
(descendants [h] v) → hash? |
h : hierarchy? = (global-hierarchy) |
v : any/c |
A transitive version of children. Retrieves all descendants of v registered in h or in the global default hierarchy, if the single argument form is used. This is the counterpart of ancestors.
Returns a hash table mapping all the descendants 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:
child and parent are equal?.
parent is an interface and child extends it.
parent is a registered ancestor of child in the type hierarchy.
child is an interface and extends some other interface that is a registered descendant of parent in the type hierarchy.
child and parent both satisfy dict?, all keys from the parent are present in the child and all values in the child are derived? from the corresponding values in the parent.
(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.
(underive child parent) → void? |
child : any/c |
parent : (not/c (or/c class? interface?)) |
(underive h child parent) → hierarchy? |
h : hierarchy? |
child : any/c |
parent : (not/c (or/c class? interface?)) |
Removes a direct parent of a child from a value hierarchy. Updates the descendants and ancestors relations accordingly.
Before the old relation is unregistered, 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 isn’t derive from the parent, 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.