ASOrchardStructure.mesa
Last Edited by Arnon: May 16, 1989 4:03:10 pm PDT
Structure Constructor: make a Structure whose underlying set is an orchard of (possibly labeled, possibly labeled heap-ordered) rooted n-ary trees
DIRECTORY
Rope,
AlgebraClasses,
ASVariableSequences;
ASOrchardStructure: CEDAR DEFINITIONS
~ BEGIN
Element Representation
Orchard: TYPE = AlgebraClasses.Object;
OrchardData: TYPE = LIST OF OrchardTerm;
Distributed representation, modelled on a distributed polynomial rep. The terms of a nonNIL Orchard are sorted in order of increasing hash code. The Nil Orchard is represented by OrchardData = NIL.
OrchardTerm: TYPE = REF OrchardTermRec;
TermRec: TYPE = RECORD [
coefficient: AlgebraClasses.Object - expected to be either an Int or a Real
tree: Tree,
];
Tree: TYPE = AC.Object;
TreeData: TYPE = REF TreeDataRec;
TreeDataRec: TYPE = RECORD [
parent: Tree ← NIL, -- parent tree; NIL iff this node is root
children: LIST OF Tree ← NIL, -- NIL iff this node is a leaf
label: ASVariables.Variable ← NIL, -- nonNIL iff this is a labeled tree
key: ACInts.Int ← NIL -- nonNIL iff this is a heap-ordered tree
];
Structure Representation
OrchardStructureData: TYPE = REF OrchardStructureDataRec;
OrchardStructureDataRec: TYPE = RECORD [
coeffRing: AlgebraClasses.Object, -- expected to be either Ints or Reals
labels: ASVariableSequences.VariableSequence ← NIL, -- NIL labels iff these are unlabeled trees
heapOrdered: BOOL
];
Structure Constructors
MakeOrchardStructure: AlgebraClasses.OrchardStructureConstructor;
MakeNameStructureData: PROC [data1, data2] RETURNS [structure: Object];
MakeNameStructure: PROC [data1, data2] RETURNS [structure: Object];
Arguments are the fields of a Structure Instance Data.
RETURN[AlgebraClasses.MakeObject[class, MakeNameStructureData[data1, data2] ] ]
Structure Selectors
GetNameStructureData: AlgebraClasses.GetStructureDataProc;
AlgebraClasses.GetStructureDataProc: TYPE = PROC [structure: Object] RETURNS [StructureData: REF ANY];
output is a NameStructureData
Data1: AlgebraClasses.UnaryOp;
Input is a structure, output is the data1 field of its StructureData (assuming this field is an Object)
Data2: AlgebraClasses.UnaryOp;
Input is a structure, output is the data2 field of its StructureData (assuming this field is an Object)
Structure Operations
Flavor: AlgebraClasses.FlavorOp;
AlgebraClasses.FlavorOp: TYPE = PROC [object: Object] RETURNS [flavor: Flavor];
AlgebraClasses.flavor: TYPE = { StructureElement, Structure, Class};
Looks (with ISTYPE) for ElementNameData and NameStructureData.
Should be in both StructureElement and Structure class records.
StructureToRope: AlgebraClasses.ToRopeOp;
A functional expression that can be parsed and evaluated to reconstruct the structure
StructureName: AlgebraClasses.ToRopeOp;
A short identifying name, e.g. "Q" for the rational numbers
StructureLBKey: AlgebraClasses.ToRopeOp;
LoganBerry primaryKey attribute value, for searching for this object in a LoganBerry db. Such keys are generated when an Object is to be offlined.
StructureData: AlgebraClasses.UnaryToListOp;
selector: returns LIST[data1, data2] of a Name Structure
IsNameStructure: AlgebraClasses.UnaryPredicate;
Element Constructors
MakeOrchard: AlgebraClasses.ListImbedOp;
Arguments are a list of OrchardTerms, assumed to be correctly ordered by hash code.
MakeElementNameData: PROC [field1, field2] RETURNS [elementData: ElementNameData];
Element Selectors
GetNameElementData: AlgebraClasses.GetElementDataProc;
AlgebraClasses.GetElementDataProc: TYPE = PROC [structureElement: Object] RETURNS [ElementData: REF ANY];
output is a ElementNameData
Field1: AlgebraClasses.UnaryOp;
Input is a structure, output is the field1 field of its ElementData (assuming this field is an Object)
Field2: AlgebraClasses.UnaryOp;
Input is a structure, output is the field2 field of its ElementData (assuming this field is an Object)
Element Conversion and IO
WidenOther: AlgebraClasses.BinaryOp;
Previously called "Recast"
Arguments are a StructureElement and a Structure. firstArg is intended to be an element of a "narrower" Structure than the one being defined by this interface, and secondArg is intended to be a Structure of the kind being defined by this interface. We attempt to widen firstArg to be an element of secondArg.
If CanWidenOther[firstArg], then either we return firstArg unchanged (it is already an element of secondArg), or we create and return a new Object belonging to secondArg, i.e. we never modify the input Object.
CanWidenOther: AlgebraClasses.BinaryPredicate;
Previously called "CanRecast"
Arguments are either a StructureElement and a Structure, or two Structures. firstArg is intended to be an element of, or be, a "narrower" Structure than the one being defined by this interface, and secondArg is intended to be a Structure of the kind being defined by this interface. Returns true if firstArg can be widened to be an element of secondArg.
NarrowOther: AlgebraClasses.BinaryOp;
Arguments are a StructureElement and a Structure. firstArg is intended to be an element of a "wider" Structure than the one being defined by this interface, and secondArg is intended to be a Structure of the kind being defined by this interface. We attempt to narrow firstArg to be an element of secondArg.
If CanNarrowOther[firstArg], then either we return firstArg unchanged (it is already an element of secondArg), or we create and return a new Object belonging to secondArg, i.e. we never modify the input Object.
CanNarrowOther: AlgebraClasses.BinaryPredicate;
Arguments are either a StructureElement and a Structure, or two Structures. firstArg is intended to be an element of, or be, a "wider" Structure than the one being defined by this interface, and secondArg is intended to be a Structure of the kind being defined by this interface. Returns true if firstArg can be narrowed to be an element of secondArg.
WidenThis: AlgebraClasses.UnaryOp;
Argument is a StructureElement belonging to a Structure of the kind being defined by this interface. Either we return it unchanged, or we widen it to be an element of some "wider" Structure. In the latter case, we create a new Object, i.e. don't modify input. However it is expected that only General Expressions could ever be returned unchanged by a WidenThis proc, since it should be possible to widen anything else into a General Expression.
For example, an integer can be widened to be a rational number.
Usually a (nontrivial) WidenThis proc is written by knowing some tag with which the intended structure can be looked up (so we don't need to mention the Cedar interface that defines it), and then just applying that Structure's WidenOther proc to the argument.
The basic AlgebraStructures method lookup procedure is to look for a method in this Object's class and all its superclasses, then set x ← WidenThis[input]; IF x.class.Equal[x, input] then FAIL else recursive call on x.
NarrowThis: AlgebraClasses.UnaryOp;
Argument is a StructureElement belonging to a Structure of the kind being defined by this interface. Either we return it unchanged, or we narrow it to be an element of the narrowest possible "narrower" Structure. In the latter case, we create a new Object, i.e. don't modify input.
For example, the NarrowThis proc for the rational numbers should return a BigInt for 3/1, but (the unchanged input argument) BigRat for 3/5.
Expression evaluators are examples of NarrowThis procs. The fact that typically NarrowThis[V: Variable] looks for a value associated with V in some "environment", and if found, returns value.class.NarrowThis[value], is a detail that is entirely consistent with this assertion.
WidenToGeneralExpression: AlgebraClasses.UnaryOp;
Previously called "ToExpr: AlgebraClasses.ToExprOp";
Optional. A short cut to successive aplication of WidenThis procs until General Expressions reached.
LegalFirstChar: AlgebraClasses.LegalFirstCharOp;
ElementRead: AlgebraClasses.ReadOp;
The Domain-dependent parser
ElementFromRope: AlgebraClasses.FromRopeOp;
ElementToRope: AlgebraClasses.ToRopeOp;
Write out an Element in such a form that the Domain-dependent parser can read it back in.
ElementLBKey: AlgebraClasses.ToRopeOp;
LoganBerry primaryKey attribute value, for searching for this object in a LoganBerry db. Such keys are generated when an Object is to be offlined.
ElementWrite: AlgebraClasses.WriteOp;
Element Operations
Select: AlgebraClasses.BinaryOp;
Args are an Orchard and hash code (an Int), returns the OrchardTerm in that tree with that hash code; return NIL if no such OrchardTerm found.
Insert: AlgebraClasses.BinaryOp;
Args are an OrchardTerm and an Orchard, returns the Orchard resulting from inserting that OrchardTerm into the given Orchard.
Length: AlgebraClasses.UnaryOp;
Arg is an Orchard, returns the length (# of terms) in it (an Int).
UnaryOp: AlgebraClasses.UnaryOp;
END.