DIRECTORY SafeStorage, IO, Atom, Rope, Basics, SymTab, Imager, MathExpr; MathObjects: CEDAR DEFINITIONS = BEGIN ROPE: TYPE = Rope.ROPE; STREAM: TYPE = IO.STREAM; Object: TYPE = REF ObjectRep; ObjectRep: TYPE; -- internal concrete rep Method: TYPE = REF MethodRep; MethodRep: TYPE; MethodDictionary: TYPE = REF MethodDictionaryRep; MethodDictionaryRep: TYPE; 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; ApplyMethod: PROC [method: Method, argList: LIST OF REF] RETURNS[value: REF]; StaticTypes: Object; -- SystemObject StaticTypesData: TYPE ~ REF StaticTypesDataRep; StaticTypesDataRep: TYPE; -- probably a RefTab of method static type names and associated applicator procs; user augmentable 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}; 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]; 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]; DefaultDesiredArgStructures: UnaryToListOp; GetMethodAndRecastArgs: PROC [methodSelector: ATOM, structure: Object, inArgs: LIST OF Object] RETURNS [ok: BOOL, method: Method, outArgs: LIST OF Object _ NIL]; RecastArgs: PROC [method: Method, structure: Object, inArgs: LIST OF Object] RETURNS [ok: BOOL, outArgs: LIST OF Object _ NIL]; 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]; PrintNameProc: TYPE = PROC [structure: Object] RETURNS [Rope.ROPE]; -- redundant with ToRopeOp StructureToExprOp: TYPE = PROC [structure: Object] RETURNS [out: EXPR]; StructureEqualityTest: TYPE = PROC [thisStructure, otherStructure: Object] RETURNS [BOOL]; StructureRankOp: TYPE = PROC [structure: Object] RETURNS [CARDINAL]; ReportOpsProc: TYPE = PROC [structure: Object] RETURNS [opNames: LIST OF Rope.ROPE, refOps: LIST OF REF]; BinaryStructureLUBOp: TYPE = PROC [firstStructure, secondStructure: Object] RETURNS [LUBStructure: Object]; StructureFromSetConstructor: TYPE = PROC [set: Object] RETURNS [structure: Object]; VectorStructureConstructor: TYPE = PROC [coordinateStructure: Object, dimension: NAT, row: BOOL _ TRUE] RETURNS [vectorStructure: Object]; SequenceStructureConstructor: TYPE = PROC [elementStructure: Object, row: BOOL _ TRUE] RETURNS [sequenceStructure: Object]; MatrixStructureConstructor: TYPE = PROC [elementStructure: Object, nRows, nCols: NAT] RETURNS [matrixStructure: Object]; PolynomialStructureConstructor: TYPE = PROC [coeffRing, variableSeq: Object] RETURNS [polynomialStructure: Object]; MakeStructure: PROC [name: Rope.ROPE, class: Object, instanceData: REF] RETURNS[structure: Object]; LegalFirstCharOp: TYPE = PROC [char: CHAR, structure: Object] RETURNS [BOOL]; 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]; 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]; ElementRankOp: TYPE = PROC [arg: Object] RETURNS [CARDINAL]; Display2DOp: TYPE = PROC [object: Object, context: Imager.Context, dotWidth, segmentWidth: REAL]; Copy: UnaryOp; ElementOf: PROC [object: Object, structure: Object] RETURNS [BOOL]; UnaryImbedOp: TYPE = PROC [in: Object, structure: Object] RETURNS [out: Object]; BinaryImbedOp: TYPE = PROC [data1: Object, data2: REF, structure: Object] RETURNS [out: Object]; ListImbedOp: TYPE = PROC [data: LIST OF Object, structure: Object] RETURNS [out: Object]; MatrixImbedOp: TYPE = PROC [elements: LIST OF Object, structure: Object] RETURNS [out: Object]; END. † MathObjects.mesa Copyright c 1989 by Xerox Corporation. All rights reserved. Arnon, August 28, 1989 1:42:36 pm PDT Types From Referenced Interfaces Object Type Definitions 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. 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 Method Application 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 Need to declare aplicator procs in the right places (e.g. FromINTOp in Ints), for each of the following Operations on Objects - Static Types Method Operations Does method lookup RETURN[ LIST[structure] ]; (arg is expected to be a Structure) Lookup method in structure, and recast args Try to recast args LookupMethodForStructure, RETURN[NARROW[ApplyNoLkpNoRecastRef]]. Error if anything at all goes wrong. Structure Operation Types Identify the particular structure to the world. Test whether some other structure is the same algebraic domain as this one For things like ring characteristic (smallest positive integer k such that k*1 = 0; 0 if k infinite) and vector space dimension. Report structure operations to outside world, e.g. a user interface Should be made a concrete proc to be applied to method dictionaries If either Structure NIL, return other Structure Constructor Types Make a Structure whose (finite) underlying set is the given argument. 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. A particular sequence structure is defined by its elementStructure, which can be any Structure, and whether its elements are displayed as rows or columns. A particular matrix structure is defined by its elementStructure and its nRows, nCols. elementStructure can be a ring, field, algebra, or divisionAlgebra. 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 StructureElement Operation Types True if char is legal first char in an external rep of a structure element. Since no object arg, need a hook to structure For things like determinant and coefficient extraction For things like degree functions in euclidean domains, rank of matrices Display an object in a 2D context. StructureElement Operations True if object is an element of structure. (check equality of its structure's name with this structure's name) StructureElement Creation Types Imbed in as an element of structure Construct an element of structure from data1 and data2. Sample use: constructing a term of a polynomial. Construct an element of a point, sequence, or vector Structure from data 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 Κ •NewlineDelimiter ™codešœ Οc™Kšœ Οmœ1™K˜—š ‘œŸœŸœŸœŸœ˜9K™—š‘œŸœŸœ˜*K˜—š ‘ œŸœŸœŸœ ŸœŸœ ˜JK˜—š‘œŸœŸœŸœ˜MK˜—š ‘œŸœŸœŸœŸœ˜JK˜—š ‘ œŸœŸœŸœŸœ ˜RK˜—š‘œŸœŸœŸœ˜@K˜—š ‘ œŸœŸœŸœŸœ˜WK˜—š ‘œŸœŸœŸœŸœ%˜kK˜—š‘ œŸœŸœ)Ÿœ˜XK˜—š ‘œŸœŸœ)ŸœŸœ˜bK˜—Kš‘ œŸœŸœ4Ÿœ˜f—š‘™š‘ œŸœŸœ ŸœŸœŸœŸœ ˜„J˜—š ‘œŸœŸœŸœŸœŸœ ˜]J™J˜—š‘œ˜+Jšœ?™?J™—š‘œŸœŸœŸœŸœ ŸœŸœŸœŸœ Ÿœ˜‘Kšœ+™+K™—š‘ œŸœ-ŸœŸœ ŸœŸœ ŸœŸœ Ÿœ˜Kšœ™K˜—š ‘œŸœŸœŸœŸœŸœ˜dJ˜—š ‘œŸœŸœŸœŸœ ˜^J˜—š ‘œŸœŸœŸœŸœ ˜\J˜—š‘œŸœŸœŸœ ˜XJ˜—š‘œŸœŸœ˜XJ˜—š‘œŸœ/Ÿœ˜hJ˜—š‘œŸœ(ŸœŸœ ˜lJ˜—š ‘œŸœŸœŸœŸœŸœ ˜aJ˜—š ‘œŸœŸœŸœ ŸœŸœ˜UJ˜—š ‘œŸœ.ŸœŸœ ŸœŸœ˜fJ˜—š‘œŸœŸœŸœŸœ ŸœŸœ˜lJšœ@™@Jšœ$™$J˜——š‘™š ‘ œŸœŸœŸœŸœ˜^Kšœ œ™/K˜—š ‘œŸœŸœŸœŸœ˜GK˜—š ‘œŸœŸœ)ŸœŸœ˜ZK™JK˜—š ‘œŸœŸœŸœŸœ˜DKšœ%\™K™—š‘ œŸœŸœŸœ ŸœŸœŸœ ŸœŸœŸœ˜iKšœC™CK™CK™—š‘œŸœŸœ+Ÿœ˜kK™%——š‘™š‘œŸœŸœŸœ˜SJšœE™EK˜—š‘œŸœŸœ*ŸœŸœŸœŸœ˜ŠJšœͺ™ͺK˜—š ‘œŸœŸœ!ŸœŸœŸœ˜{Jšœš™šK˜—š ‘œŸœŸœ*ŸœŸœ˜xJšœš™šK˜—š‘œŸœŸœ"Ÿœ˜sJšœP™PJšœ<™