NameStructure.mesa
Last Edited by Name.pa: Date
Structure Constructor: Comment
DIRECTORY
Rope,
AlgebraClasses;
ASNameStructure: CEDAR DEFINITIONS
~ BEGIN
Element Representation
ElementName: TYPE = AlgebraClasses.Object;
Comment
ElementNameData: TYPE = REF ElementNameDataRec;
ElementNameDataRec: TYPE = RECORD [
field1: Type,
field2: Type
];
Structure Representation
NameStructureData: TYPE = REF NameStructureDataRec;
NameStructureDataRec: TYPE = RECORD [
data1: AlgebraClasses.Object, -- Comment
data2: AlgebraClasses.Object -- Comment
];
Structure Constructors
MakeNameStructureData: PROC [data1, data2] RETURNS [structureData: NameStructureData];
Arguments are the fields of a Structure Instance Data
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
MakeName: AlgebraClasses.ListImbedOp;
Arguments are the fields of an ElementNameData.
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
BinaryOp: AlgebraClasses.BinaryOp;
UnaryOp: AlgebraClasses.UnaryOp;
END.