MathObjects.mesa
Copyright © 1989 by Xerox Corporation. All rights reserved.
Arnon, August 28, 1989 1:42:36 pm PDT
DIRECTORY
SafeStorage,
IO,
Atom,
Rope,
Basics,
SymTab,
Imager,
MathExpr;
MathObjects:
CEDAR DEFINITIONS
Types From Referenced Interfaces
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
Object Type Definitions
Object: TYPE = REF ObjectRep;
ObjectRep: TYPE; -- internal concrete rep
Method: TYPE = REF MethodRep;
MethodRep: TYPE;
MethodDictionary:
TYPE =
REF MethodDictionaryRep;
Conceptually, a MethodDictionary is a data structure containing [key, Method] pairs, on which some search algorithm is defined that, given a key, either returns a corresponding Method, or reports that none can be found.
It is not required that there be at most one [key, Method] pair for a given key in a MethodDictionary. In fact, multiple [key, Method] pairs with the same key can be stored so as to be found in a particular order. It is the search proc implementor's job to determine how to handle the possibility of multiple [key, Method] pairs with the same key.
MethodDictionaryRep:
TYPE;
We have in mind multiple possible reps, e.g. Atom.PropList, or more structured, non-flat, e.g. tree of methods, or a tree of Atom.PropList
Should MethodDictionary's, or some portion of the info in them, be "externalizable" , or Objects, so that a domain or category can report info about itself?
A method's methodKey, i.e. methodSelector, should serve as the method's "name" for any external purpose, e.g. user menu entry, or "logging" of a method application; should be identical to what some parser expects to be able to construct a MethodApplication object.
Note that we need to plan NOW for universal names, so we don't get into $sum, $Sum, $add confusions.
System (Global) Objects
SystemObjects is the .class for all SystemObject's. Its .data records all currently known SystemObject's. Its .class is some special Object SystemObjectsClass, which we insist is never manipulated in any way, and whose .class is NIL) and its flavor is $SystemRoot. Its usefulness is that it provides a single, comprehensive access point to system state (which indeed should be definable as the set of all SystemObject's), which can thus be externalized as the composition (e.g. list) of the externalizations of the individual SystemObject's.
SystemObjects' .methods provides methods for access to the constituents of its Elements (i.e. SystemObject's), e.g. search, a $flavor method (returns $SystemObject), and an $eltDisplay method.
Thus we mandate an architecture that imposes some limitation of generality on class relationships. We assert that there is no useful value to be had by explicitly creating a class of all Objects. Instead we assert that every (Math)Object has a certain flavor, which (currently) is one of:
$Element
$Domain
$View
$Category
$Environment
$Package
$SystemObject
$SystemRoot
For the first ($Element), we need know no more than what Structure it belongs to. For the next five ($Domain, $View, $Category, $Environment, or $Package), any Object of that flavor is an element of some corresponding SystemObject, and that is the most we need to know. Any $SystemObject Object is an element of SystemObjects, and that is all we need to know. SystemObjects is the unique Object of flavor $SystemRoot. The only other (kind of) Object that does, or ever can, exist in the system is SystemObjectsClass
SystemObjects: Object;
SystemObjectsData: TYPE ~ REF SystemObjectsDataRep; -- probably could be like a StructureDataRep; includes a MethodDictionary (including an $eltFlavor method for SystemObject's), and a LIST of all current SystemObject's
SystemObjectsDataRep: TYPE;
EnumerateSystemObjects: PROC RETURNS [LIST OF Object]; -- maybe unneeded
SystemObjectsToRope: ToRopeOp;
Method Application
ApplyMethod:
PROC [method: Method, argList:
LIST
OF
REF]
RETURNS[value:
REF];
It is assumed that argList conforms to method's runtimeType (no check).
Note that args and return value, if not Objects, must be at least REF's. I.e. the ability of this method apply procedure to handle Cedar types is limited to REF's. Thus all methods to be invoked by the general method apply machinery must meet this constraint.
Static Types
StaticTypes: Object; -- SystemObject
StaticTypesData: TYPE ~ REF StaticTypesDataRep;
StaticTypesDataRep: TYPE; -- probably a RefTab of method static type names and associated applicator procs; user augmentable
Need to declare aplicator procs in the right places (e.g. FromINTOp in Ints), for each of the following
MethodType: TYPE = {Value, SideEffect, TrueNullaryOp, NullaryOp, UnaryOp, BinaryOp, BinaryMixedOp, TernaryOp, TernaryMixedOp, QuaternaryOp, LegalFirstCharOp, ReadOp, FromRopeOp, ToRopeOp, ToExprOp, FromExprOp, FromBOOLOp, FromINTOp, UnaryPredicate, BinaryPredicate, CompareToZeroOp, BinaryCompareOp, StructuredToGroundOp, ElementRankOp, UnaryImbedOp, BinaryImbedOp, ListImbedOp, MatrixImbedOp, StructureFromSetConstructor, VectorStructureConstructor, SequenceStructureConstructor, MatrixStructureConstructor, PolynomialStructureConstructor};
Operations on Objects - Static Types
SideEffect:
TYPE =
PROC []
RETURNS [];
TrueNullaryOp:
TYPE =
PROC []
RETURNS [result: Object];
UnaryOp:
TYPE =
PROC [arg: Object]
RETURNS [result: Object];
UnaryToRefOp:
TYPE =
PROC [arg: Object]
RETURNS [result:
REF];
UnaryPredicate:
TYPE =
PROC [arg: Object]
RETURNS [
BOOL];
UnaryInPlaceOp:
TYPE =
PROC [arg: Object];
UnaryToListOp:
TYPE =
PROC [arg: Object]
RETURNS [result:
LIST
OF Object];
BinaryOp:
TYPE =
PROC [firstArg, secondArg: Object]
RETURNS [result: Object];
BinaryPredicate:
TYPE =
PROC [firstArg, secondArg: Object]
RETURNS [
BOOL];
EqualityOp:
TYPE =
PROC [firstArg, secondArg: Object]
RETURNS [
BOOL];
-- redundant
BinaryInPlaceOp:
TYPE =
PROC [firstArg: Object, secondArg:
REF];
BinaryMixedOp:
TYPE =
PROC [firstArg: Object, secondArg:
REF]
RETURNS [result: Object];
BinaryToPairOp:
TYPE =
PROC [firstArg: Object, secondArg:
REF]
RETURNS [firstResult, secondResult: Object];
TernaryOp:
TYPE =
PROC [firstArg, secondArg, thirdArg: Object]
RETURNS [result: Object];
TernaryMixedOp:
TYPE =
PROC [firstArg, secondArg: Object, thirdArg:
REF]
RETURNS [result: Object];
QuaternaryOp: TYPE = PROC [firstArg, secondArg, thirdArg, fourthArg: Object] RETURNS [result: Object];
Method Operations
MakeMethod:
PROC [type: MethodType, operator:
BOOL, value:
REF, desiredArgStructures:
REF UnaryToListOp, doc:
ROPE]
RETURNS[Method];
DesiredArgStructures:
PROC [methodSelector:
ATOM, structure: Object]
RETURNS[
LIST
OF Object];
Does method lookup
DefaultDesiredArgStructures: UnaryToListOp;
RETURN[ LIST[structure] ]; (arg is expected to be a Structure)
GetMethodAndRecastArgs:
PROC [methodSelector:
ATOM, structure: Object, inArgs:
LIST
OF Object]
RETURNS [ok:
BOOL, method: Method, outArgs:
LIST
OF Object ←
NIL];
Lookup method in structure, and recast args
RecastArgs:
PROC [method: Method, structure: Object, inArgs:
LIST
OF Object]
RETURNS [ok:
BOOL, outArgs:
LIST
OF Object ←
NIL];
Try to recast args
ApplyLegalFirstCharMethod:
PROC [method: Method, char:
CHAR, structure: Object ←
NIL]
RETURNS[
BOOL];
ApplyFromRopeMethod:
PROC [method: Method, in:
ROPE, structure: Object ←
NIL]
RETURNS[Object];
ApplyReadMethod:
PROC [method: Method, in:
STREAM, structure: Object ←
NIL]
RETURNS[Object];
ApplyFromExprMethod:
PROC [method: Method, in:
EXPR, structure: Object]
RETURNS[Object];
ApplyCompareToZeroMethod:
PROC [method: Method, arg: Object]
RETURNS[Basics.Comparison];
ApplyBinaryCompareMethod:
PROC [method: Method, firstArg, secondArg: Object]
RETURNS[Basics.Comparison];
ApplyBinaryImbedMethod:
PROC [method: Method, data1: Object, data2:
REF, structure: Object]
RETURNS[Object];
ApplyMixedMethod:
PROC [method: Method, objectArgs:
LIST
OF Object, refArg:
REF]
RETURNS[Object];
ApplyPredNoLkpNoRecast:
PROC [method: Method, argList:
LIST
OF Object]
RETURNS[
BOOL];
ApplyPredNoLkpRecast:
PROC [method: Method, structure: Object, argList:
LIST
OF Object]
RETURNS[
BOOL];
ApplyPredLkpNoRecast:
PROC [methodSelector:
ATOM, structure: Object, argList:
LIST
OF Object]
RETURNS[
BOOL];
LookupMethodForStructure, RETURN[NARROW[ApplyNoLkpNoRecastRef]].
Error if anything at all goes wrong.
Structure Operation Types
PrintNameProc:
TYPE =
PROC [structure: Object]
RETURNS [Rope.
ROPE];
-- redundant with ToRopeOp
Identify the particular structure to the world.
StructureToExprOp:
TYPE =
PROC [structure: Object]
RETURNS [out:
EXPR];
StructureEqualityTest:
TYPE =
PROC [thisStructure, otherStructure: Object]
RETURNS [
BOOL];
Test whether some other structure is the same algebraic domain as this one
StructureRankOp:
TYPE =
PROC [structure: Object]
RETURNS [
CARDINAL];
For things like ring characteristic (smallest positive integer k such that k*1 = 0; 0 if k infinite) and vector space dimension.
ReportOpsProc:
TYPE =
PROC [structure: Object]
RETURNS [opNames:
LIST
OF Rope.
ROPE, refOps:
LIST
OF
REF];
Report structure operations to outside world, e.g. a user interface
Should be made a concrete proc to be applied to method dictionaries
BinaryStructureLUBOp:
TYPE =
PROC [firstStructure, secondStructure: Object]
RETURNS [LUBStructure: Object];
If either Structure NIL, return other
Structure Constructor Types
StructureFromSetConstructor:
TYPE =
PROC [set: Object]
RETURNS [structure: Object];
Make a Structure whose (finite) underlying set is the given argument.
VectorStructureConstructor:
TYPE =
PROC [coordinateStructure: Object, dimension:
NAT, row:
BOOL ←
TRUE]
RETURNS [vectorStructure: Object];
A particular vector structure is defined by its coordinateStructure, which can be any Structure, its dimension, and whether its elements are displayed as rows or columns.
SequenceStructureConstructor:
TYPE =
PROC [elementStructure: Object, row:
BOOL ←
TRUE]
RETURNS [sequenceStructure: Object];
A particular sequence structure is defined by its elementStructure, which can be any Structure, and whether its elements are displayed as rows or columns.
MatrixStructureConstructor:
TYPE =
PROC [elementStructure: Object, nRows, nCols:
NAT]
RETURNS [matrixStructure: Object];
A particular matrix structure is defined by its elementStructure and its nRows, nCols. elementStructure can be a ring, field, algebra, or divisionAlgebra.
PolynomialStructureConstructor:
TYPE =
PROC [coeffRing, variableSeq: Object]
RETURNS [polynomialStructure: Object];
A particular polynomial structure is defined by its coeffRing and its variables.
coeffRing can be a ring, field, algebra, or divisionAlgebra.
variableSeq is a sequence of any length, and the right thing happens.
Structure Operations
MakeStructure: PROC [name: Rope.ROPE, class: Object, instanceData: REF] RETURNS[structure: Object];
StructureElement Operation Types
LegalFirstCharOp:
TYPE =
PROC [char:
CHAR, structure: Object]
RETURNS [
BOOL];
True if char is legal first char in an external rep of a structure element.
ReadOp:
TYPE =
PROC [in:
IO.
STREAM, structure: Object ←
NIL]
RETURNS [out: Object];
FromRopeOp:
TYPE =
PROC [in: Rope.
ROPE, structure: Object ←
NIL]
RETURNS [out: Object];
ToRopeOp:
TYPE =
PROC [in: Object]
RETURNS [out: Rope.
ROPE];
WriteOp:
TYPE =
PROC [stream:
IO.
STREAM, in: Object];
FromExprOp:
TYPE =
PROC [in:
EXPR, structure: Object]
RETURNS [out: Object];
ToExprOp:
TYPE =
PROC [in: Object]
RETURNS [out:
EXPR];
FromBOOLOp:
TYPE =
PROC [in:
BOOL, structure: Object ←
NIL]
RETURNS [out: Object];
FromINTOp:
TYPE =
PROC [in:
INT, structure: Object ←
NIL]
RETURNS [out: Object];
NullaryOp:
TYPE =
PROC[structure: Object]
RETURNS [result: Object];
Since no object arg, need a hook to structure
CompareToZeroOp:
TYPE =
PROC [arg: Object]
RETURNS [Basics.Comparison];
BinaryCompareOp:
TYPE =
PROC [firstArg, secondArg: Object]
RETURNS [Basics.Comparison];
StructuredToGroundOp:
TYPE =
PROC [structuredElt: Object]
RETURNS [groundElement: Object];
For things like determinant and coefficient extraction
ElementRankOp:
TYPE =
PROC [arg: Object]
RETURNS [
CARDINAL];
For things like degree functions in euclidean domains, rank of matrices
Display2DOp:
TYPE =
PROC [object: Object, context: Imager.Context, dotWidth, segmentWidth:
REAL];
Display an object in a 2D context.
StructureElement Operations
ElementOf:
PROC [object: Object, structure: Object]
RETURNS [
BOOL];
True if object is an element of structure. (check equality of its structure's name with this structure's name)
StructureElement Creation Types
UnaryImbedOp:
TYPE =
PROC [in: Object, structure: Object]
RETURNS [out: Object];
Imbed in as an element of structure
BinaryImbedOp:
TYPE =
PROC [data1: Object, data2:
REF, structure: Object]
RETURNS [out: Object];
Construct an element of structure from data1 and data2.
Sample use: constructing a term of a polynomial.
ListImbedOp:
TYPE =
PROC [data:
LIST
OF Object, structure: Object]
RETURNS [out: Object];
Construct an element of a point, sequence, or vector Structure from data
MatrixImbedOp:
TYPE =
PROC [elements:
LIST
OF Object, structure: Object]
RETURNS [out: Object];
Construct an element of a matrix Structure from data. Assumes that correct number of elements supplied, in correct order, and that each element supplied belongs to structure.elementStructure
END.