DIRECTORY MathExpr, MathRules, MathDB, MathTypes, MathBox, Imager, Rope, Vector, MathConstructors; MathExprClassesList: CEDAR PROGRAM IMPORTS MathBox, MathRules, MathExpr, MathDB, MathConstructors ~ BEGIN EXPR: TYPE ~ MathExpr.EXPR; BOX: TYPE ~ MathBox.BOX; ROPE: TYPE ~ Rope.ROPE; VEC: TYPE ~ Vector.VEC; CompoundBoxProc: TYPE ~ MathRules.CompoundBoxProc; CompositionProc: TYPE ~ MathRules.CompositionProc; Alignment2D: TYPE ~ MathRules.Alignment2D; Offset: TYPE ~ MathRules.Offset; Size: TYPE ~ MathRules.Size; Argument: TYPE ~ MathExpr.Argument; Symbol: TYPE ~ MathExpr.Symbol; CompoundClass: TYPE ~ MathExpr.CompoundClass; FormatClass: TYPE ~ MathTypes.FormatClass; Style: TYPE ~ MathTypes.Style; MakeArgument: PROC[name: ATOM, aliases: LIST OF ATOM, size: Size] RETURNS[Argument] ~ MathExpr.MakeArgument; MakeSymbol: PROC[name: ATOM, aliases: LIST OF ATOM, size: Size, value: EXPR] RETURNS[Symbol] ~ MathExpr.MakeSymbol; MakeCompoundClass: PROC[name: ATOM, formatClass: FormatClass, description: ROPE, args: LIST OF Argument, syms: LIST OF Symbol, boxRule: CompoundBoxProc, compBox: CompositionProc, cvtAS, cvtReduce, cvtSMP, cvtOther: ROPE _ NIL] RETURNS[CompoundClass] ~ MathExpr.MakeCompoundClass; smallGap: REAL = 0.05; medGap: REAL = 0.10; bigGap: REAL = 0.25; FixedSizeBoxRule: CompoundBoxProc ~ { RETURN[boxes]; }; ParenBoxRule: CompoundBoxProc ~ { leftParenBox: BOX _ MathBox.GetBox[$leftParen, boxes]; rightParenBox: BOX _ MathBox.GetBox[$rightParen, boxes]; aBox: BOX _ MathBox.GetBox[$a, boxes]; scaleFactor: REAL _ MAX[0.25, 1.1 * aBox.Height[] / leftParenBox.Height[]]; leftParenBox _ MathBox.Scale[leftParenBox, [scaleFactor, scaleFactor]]; rightParenBox _ MathBox.Scale[rightParenBox, [scaleFactor, scaleFactor]]; RETURN[LIST[aBox, leftParenBox, rightParenBox]]; }; CurlyBoxRule: CompoundBoxProc ~ { leftCurlyBox: BOX _ MathBox.GetBox[$leftCurly, boxes]; rightCurlyBox: BOX _ MathBox.GetBox[$rightCurly, boxes]; aBox: BOX _ MathBox.GetBox[$a, boxes]; scaleFactor: REAL _ MAX[0.25, 1.1 * aBox.Height[] / leftCurlyBox.Height[]]; leftCurlyBox _ MathBox.Scale[leftCurlyBox, [scaleFactor, scaleFactor]]; rightCurlyBox _ MathBox.Scale[rightCurlyBox, [scaleFactor, scaleFactor]]; RETURN[LIST[aBox, leftCurlyBox, rightCurlyBox]]; }; SquareBoxRule: CompoundBoxProc ~ { leftSquareBox: BOX _ MathBox.GetBox[$leftSquare, boxes]; rightSquareBox: BOX _ MathBox.GetBox[$rightSquare, boxes]; aBox: BOX _ MathBox.GetBox[$a, boxes]; scaleFactor: REAL _ MAX[0.25, 1.1 * aBox.Height[] / leftSquareBox.Height[]]; leftSquareBox _ MathBox.Scale[leftSquareBox, [scaleFactor, scaleFactor]]; rightSquareBox _ MathBox.Scale[rightSquareBox, [scaleFactor, scaleFactor]]; RETURN[LIST[aBox, leftSquareBox, rightSquareBox]]; }; minParenSize: REAL = 0.5; parensToArgs: REAL = 1.2; -- scale factor UnaryFunctionBoxRule: CompoundBoxProc ~ { fBox: BOX _ MathBox.GetBox[$f, boxes]; funSpaceBox: BOX _ MathBox.GetBox[$funSpace, boxes]; lParenBox: BOX _ MathBox.GetBox[$leftParen, boxes]; arg1Box: BOX _ MathBox.GetBox[$arg1, boxes]; rParenBox: BOX _ MathBox.GetBox[$rightParen, boxes]; scaleFactor: REAL _ MAX[minParenSize, parensToArgs * arg1Box.Height[] / lParenBox.Height[]]; lParenBox _ MathBox.Scale[lParenBox, [scaleFactor, scaleFactor]]; rParenBox _ MathBox.Scale[rParenBox, [scaleFactor, scaleFactor]]; RETURN[LIST[fBox, funSpaceBox, lParenBox, arg1Box, rParenBox] ]; }; BinaryFunctionBoxRule: CompoundBoxProc ~ { fBox: BOX _ MathBox.GetBox[$f, boxes]; funSpaceBox: BOX _ MathBox.GetBox[$funSpace, boxes]; lParenBox: BOX _ MathBox.GetBox[$leftParen, boxes]; arg1Box: BOX _ MathBox.GetBox[$arg1, boxes]; comma12Box: BOX _ MathBox.GetBox[$comma12, boxes]; arg12SpaceBox: BOX _ MathBox.GetBox[$arg12Space, boxes]; arg2Box: BOX _ MathBox.GetBox[$arg2, boxes]; rParenBox: BOX _ MathBox.GetBox[$rightParen, boxes]; scaleFactor: REAL _ MAX[ minParenSize, parensToArgs * MAX[arg1Box.Height[], arg2Box.Height[] ] / lParenBox.Height[] ]; lParenBox _ MathBox.Scale[lParenBox, [scaleFactor, scaleFactor]]; comma12Box _ MathBox.Scale[comma12Box, [scaleFactor, scaleFactor]]; rParenBox _ MathBox.Scale[rParenBox, [scaleFactor, scaleFactor]]; RETURN[LIST[fBox, funSpaceBox, lParenBox, arg1Box, comma12Box, arg12SpaceBox, arg2Box, rParenBox] ]; }; TernaryFunctionBoxRule: CompoundBoxProc ~ { fBox: BOX _ MathBox.GetBox[$f, boxes]; funSpaceBox: BOX _ MathBox.GetBox[$funSpace, boxes]; lParenBox: BOX _ MathBox.GetBox[$leftParen, boxes]; arg1Box: BOX _ MathBox.GetBox[$arg1, boxes]; comma12Box: BOX _ MathBox.GetBox[$comma12, boxes]; arg12SpaceBox: BOX _ MathBox.GetBox[$arg12Space, boxes]; arg2Box: BOX _ MathBox.GetBox[$arg2, boxes]; comma23Box: BOX _ MathBox.GetBox[$comma23, boxes]; arg23SpaceBox: BOX _ MathBox.GetBox[$arg23Space, boxes]; arg3Box: BOX _ MathBox.GetBox[$arg3, boxes]; rParenBox: BOX _ MathBox.GetBox[$rightParen, boxes]; scaleFactor: REAL _ MAX[ minParenSize, parensToArgs * MAX[arg1Box.Height[], arg2Box.Height[], arg3Box.Height[] ] / lParenBox.Height[] ]; lParenBox _ MathBox.Scale[lParenBox, [scaleFactor, scaleFactor]]; comma12Box _ MathBox.Scale[comma12Box, [scaleFactor, scaleFactor]]; comma23Box _ MathBox.Scale[comma23Box, [scaleFactor, scaleFactor]]; rParenBox _ MathBox.Scale[rParenBox, [scaleFactor, scaleFactor]]; RETURN[LIST[fBox, funSpaceBox, lParenBox, arg1Box, comma12Box, arg12SpaceBox, arg2Box, comma23Box, arg23SpaceBox, arg3Box, rParenBox] ]; }; QuaternaryFunctionBoxRule: CompoundBoxProc ~ { fBox: BOX _ MathBox.GetBox[$f, boxes]; funSpaceBox: BOX _ MathBox.GetBox[$funSpace, boxes]; lParenBox: BOX _ MathBox.GetBox[$leftParen, boxes]; arg1Box: BOX _ MathBox.GetBox[$arg1, boxes]; comma12Box: BOX _ MathBox.GetBox[$comma12, boxes]; arg12SpaceBox: BOX _ MathBox.GetBox[$arg12Space, boxes]; arg2Box: BOX _ MathBox.GetBox[$arg2, boxes]; comma23Box: BOX _ MathBox.GetBox[$comma23, boxes]; arg23SpaceBox: BOX _ MathBox.GetBox[$arg23Space, boxes]; arg3Box: BOX _ MathBox.GetBox[$arg3, boxes]; comma34Box: BOX _ MathBox.GetBox[$comma34, boxes]; arg34SpaceBox: BOX _ MathBox.GetBox[$arg34Space, boxes]; arg4Box: BOX _ MathBox.GetBox[$arg4, boxes]; rParenBox: BOX _ MathBox.GetBox[$rightParen, boxes]; scaleFactor: REAL _ MAX[ minParenSize, parensToArgs * MAX[arg1Box.Height[], arg2Box.Height[], arg3Box.Height[], arg4Box.Height[] ] / lParenBox.Height[] ]; lParenBox _ MathBox.Scale[lParenBox, [scaleFactor, scaleFactor]]; comma12Box _ MathBox.Scale[comma12Box, [scaleFactor, scaleFactor]]; comma23Box _ MathBox.Scale[comma23Box, [scaleFactor, scaleFactor]]; comma34Box _ MathBox.Scale[comma34Box, [scaleFactor, scaleFactor]]; rParenBox _ MathBox.Scale[rParenBox, [scaleFactor, scaleFactor]]; RETURN[LIST[fBox, funSpaceBox, lParenBox, arg1Box, comma12Box, arg12SpaceBox, arg2Box, comma23Box, arg23SpaceBox, arg3Box, comma34Box, arg34SpaceBox, arg4Box, rParenBox] ]; }; ListCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$car, [$comma, [right], [left]], [$comma, [origin], [origin]]], [$space, [$comma, [left], [right]], [$comma, [origin], [origin]]], [$cdr, [$space, [left], [right]], [$comma, [origin], [origin]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$car, [origin]], [$comma, [origin]]]; RETURN[tempBox, tempBoxes]; }; NullaryFunctionCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$leftParen, [$rightParen, [right], [left]], [$rightParen, [center], [center]]], [$funSpace, [$leftParen, [right], [left]], [$leftParen, [origin], [origin]]], [$f, [$funSpace, [right], [left]], [$leftParen, [origin], [origin]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$f, [origin]], [$f, [origin]]]; RETURN[tempBox, tempBoxes]; }; UnaryFunctionCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$leftParen, [$arg1, [right], [left]], [$arg1, [center], [center]]], [$rightParen, [$arg1, [left], [right]], [$leftParen, [center], [center]]], [$funSpace, [$leftParen, [right], [left]], [$arg1, [origin], [origin]]], [$f, [$funSpace, [right], [left]], [$arg1, [origin], [origin]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$f, [origin]], [$f, [origin]]]; RETURN[tempBox, tempBoxes]; }; BinaryFunctionCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$leftParen, [$arg1, [right], [left]], [$arg1, [center], [center]]], [$comma12, [$arg1, [left], [right]], [$arg1, [origin], [origin]]], [$arg12Space, [$comma12, [left], [right]], [$comma12, [origin], [origin]]], [$arg2, [$arg12Space, [left], [right]], [$arg12Space, [origin], [origin]]], [$rightParen, [$arg2, [left], [right]], [$leftParen, [center], [center]]], [$funSpace, [$leftParen, [right], [left]], [$arg1, [origin], [origin]]], [$f, [$funSpace, [right], [left]], [$arg1, [origin], [origin]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$f, [origin]], [$f, [origin]]]; RETURN[tempBox, tempBoxes]; }; TernaryFunctionCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$leftParen, [$arg1, [right], [left]], [$arg1, [center], [center]]], [$comma12, [$arg1, [left], [right]], [$arg1, [origin], [origin]]], [$arg12Space, [$comma12, [left], [right]], [$comma12, [origin], [origin]]], [$arg2, [$arg12Space, [left], [right]], [$arg12Space, [origin], [origin]]], [$comma23, [$arg2, [left], [right]], [$arg2, [origin], [origin]]], [$arg23Space, [$comma23, [left], [right]], [$comma23, [origin], [origin]]], [$arg3, [$arg23Space, [left], [right]], [$arg23Space, [origin], [origin]]], [$rightParen, [$arg3, [left], [right]], [$leftParen, [center], [center]]], [$funSpace, [$leftParen, [right], [left]], [$arg1, [origin], [origin]]], [$f, [$funSpace, [right], [left]], [$arg1, [origin], [origin]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$f, [origin]], [$f, [origin]]]; RETURN[tempBox, tempBoxes]; }; QuaternaryFunctionCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$leftParen, [$arg1, [right], [left]], [$arg1, [center], [center]]], [$comma12, [$arg1, [left], [right]], [$arg1, [origin], [origin]]], [$arg12Space, [$comma12, [left], [right]], [$comma12, [origin], [origin]]], [$arg2, [$arg12Space, [left], [right]], [$arg12Space, [origin], [origin]]], [$comma23, [$arg2, [left], [right]], [$arg2, [origin], [origin]]], [$arg23Space, [$comma23, [left], [right]], [$comma23, [origin], [origin]]], [$arg3, [$arg23Space, [left], [right]], [$arg23Space, [origin], [origin]]], [$comma34, [$arg3, [left], [right]], [$arg3, [origin], [origin]]], [$arg34Space, [$comma34, [left], [right]], [$comma34, [origin], [origin]]], [$arg4, [$arg34Space, [left], [right]], [$arg34Space, [origin], [origin]]], [$rightParen, [$arg4, [left], [right]], [$leftParen, [center], [center]]], [$funSpace, [$leftParen, [right], [left]], [$arg1, [origin], [origin]]], [$f, [$funSpace, [right], [left]], [$arg1, [origin], [origin]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$f, [origin]], [$f, [origin]]]; RETURN[tempBox, tempBoxes]; }; UnaryOpCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$aliasSpace, [$aliasUnaryOp, [left], [right]], [$aliasUnaryOp, [origin], [origin]]], [$aliasA, [$aliasSpace, [left], [right]], [$aliasSpace, [origin], [origin]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$aliasUnaryOp, [origin]], [$aliasUnaryOp, [origin]]]; RETURN[tempBox, tempBoxes]; }; BinaryOpCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; leftVertOffsetA, leftVertOffsetOp, rightVertOffsetB, rightVertOffsetOp: Offset; alignments: LIST OF Alignment2D; SELECT MathBox.GetBox[$aliasA, boxes].FormatClass[] FROM over => { leftVertOffsetA _ [origin]; leftVertOffsetOp _ [center]; }; matrix => { leftVertOffsetA _ [center]; leftVertOffsetOp _ [center]; }; ENDCASE => { leftVertOffsetA _ [origin]; leftVertOffsetOp _ [origin]; }; SELECT MathBox.GetBox[$aliasB, boxes].FormatClass[] FROM over => { rightVertOffsetB _ [origin]; rightVertOffsetOp _ [center]; }; matrix => { rightVertOffsetB _ [center]; rightVertOffsetOp _ [center]; }; ENDCASE => { rightVertOffsetB _ [origin]; rightVertOffsetOp _ [origin]; }; alignments _ LIST[ [$aliasLeftSpace, [$aliasBinOp, [right], [left]], [$aliasBinOp, [origin], [origin]]], [$aliasA, [$aliasLeftSpace, [right], [left]], [$aliasBinOp, leftVertOffsetA, leftVertOffsetOp]], [$aliasRightSpace, [$aliasBinOp, [left], [right]], [$aliasBinOp, [origin], [origin]]], [$aliasB, [$aliasRightSpace, [left], [right]], [$aliasBinOp, rightVertOffsetB, rightVertOffsetOp]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$aliasA, [origin]], [$aliasBinOp, [origin]]]; RETURN[tempBox, tempBoxes]; }; RelationCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; leftVertOffsetLHS, leftVertOffsetRel, rightVertOffsetRHS, rightVertOffsetRel: Offset; alignments: LIST OF Alignment2D; SELECT MathBox.GetBox[$aliasLHS, boxes].FormatClass[] FROM over => { leftVertOffsetLHS _ [origin]; leftVertOffsetRel _ [center]; }; matrix => { leftVertOffsetLHS _ [center]; leftVertOffsetRel _ [center]; }; ENDCASE => { leftVertOffsetLHS _ [origin]; leftVertOffsetRel _ [origin]; }; SELECT MathBox.GetBox[$aliasRHS, boxes].FormatClass[] FROM over => { rightVertOffsetRHS _ [origin]; rightVertOffsetRel _ [center]; }; matrix => { rightVertOffsetRHS _ [center]; rightVertOffsetRel _ [center]; }; ENDCASE => { rightVertOffsetRHS _ [origin]; rightVertOffsetRel _ [origin]; }; alignments _ LIST[ [$aliasLeftSpace, [$aliasRelation, [right], [left]], [$aliasRelation, [origin], [origin]]], [$aliasLHS, [$aliasLeftSpace, [right], [left]], [$aliasRelation, leftVertOffsetLHS, leftVertOffsetRel]], [$aliasRightSpace, [$aliasRelation, [left], [right]], [$aliasRelation, [origin], [origin]]], [$aliasRHS, [$aliasRightSpace, [left], [right]], [$aliasRelation, rightVertOffsetRHS, rightVertOffsetRel]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$aliasLHS, [origin]], [$aliasRelation, [origin]]]; RETURN[tempBox, tempBoxes]; }; ParenCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$leftParen, [$a, [right], [left]], [$a, [center], [center]]], [$rightParen, [$a, [left], [right]], [$a, [center], [center]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$leftParen, [origin]], [$self, [center, -0.25]]]; RETURN[tempBox, tempBoxes]; }; CurlyCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$leftCurly, [$a, [right], [left]], [$a, [center], [center]]], [$rightCurly, [$a, [left], [right]], [$a, [center], [center]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$leftCurly, [origin]], [$self, [center, -0.25]]]; RETURN[tempBox, tempBoxes]; }; SquareCompRule: CompositionProc ~ { tempBox: BOX; tempBoxes: LIST OF BOX; alignments: LIST OF Alignment2D _ LIST[ [$leftSquare, [$a, [right], [left]], [$a, [center], [center]]], [$rightSquare, [$a, [left], [right]], [$a, [center], [center]]]]; [tempBox, tempBoxes] _ MathRules.Compose[boxes, alignments, [$leftSquare, [origin]], [$self, [center, -0.25]]]; RETURN[tempBox, tempBoxes]; }; MakeUnaryOpClass: PUBLIC PROC[class, op, arg: ATOM, operation: EXPR, description: ROPE, cvtAS, cvtReduce, cvtSMP, cvtOther: ROPE _ NIL] RETURNS[CompoundClass] ~ { argArg: Argument _ MakeArgument[arg, LIST[$aliasA, $aliasHot], normal]; spaceSym: Symbol _ MakeSymbol[$Space, LIST[$aliasSpace], normal, MathConstructors.MakeSpace[$medium]]; unaryOpSym: Symbol _ MakeSymbol[op, LIST[$aliasUnaryOp], normal, operation]; RETURN[MakeCompoundClass[class, unaryOp, description, LIST[argArg], LIST[unaryOpSym, spaceSym], FixedSizeBoxRule, UnaryOpCompRule, cvtAS]]; }; MakeRelationClass: PUBLIC PROC[class, rel, lhs, rhs: ATOM, relation: EXPR, description: ROPE, cvtAS, cvtReduce, cvtSMP, cvtOther: ROPE _ NIL] RETURNS[CompoundClass] ~ { lhsArg: Argument _ MakeArgument[lhs, LIST[$aliasLHS, $aliasHot], normal]; rhsArg: Argument _ MakeArgument[rhs, LIST[$aliasRHS], normal]; relSym: Symbol _ MakeSymbol[rel, LIST[$aliasRelation], normal, relation]; leftSpace: Symbol _ MakeSymbol[$leftSpace, LIST[$aliasLeftSpace], normal, MathConstructors.MakeSpace[$thick]]; rightSpace: Symbol _ MakeSymbol[$rightSpace, LIST[$aliasRightSpace], normal, MathConstructors.MakeSpace[$thick]]; RETURN[MakeCompoundClass[class, relation, description, LIST[lhsArg, rhsArg], LIST[relSym, leftSpace, rightSpace], FixedSizeBoxRule, RelationCompRule, cvtAS]]; }; wrongBoxType: PUBLIC ERROR = CODE; InstallListClassesAA: PROC [] ~ { parenClass, curlyClass, squareClass, listClass, unaryFunctionClass, binaryFunctionClass, ternaryFunctionClass, quaternaryFunctionClass, altFunctionClass, nullaryFunctionClass, quoteClass: CompoundClass; aParenArg, aCurlyArg, aSquareArg, carArg, cdrArg, fArg, arg1, arg2, arg3, arg4: Argument; leftParenSym, rightParenSym, leftCurlySym, rightCurlySym, leftSquareSym, rightSquareSym, commaSym, listSpSym, funSpaceSym, funLParenSym, funRParenSym, altFunLP, altFunRP, arg12SpaceSym, arg23SpaceSym, arg34SpaceSym, comma12Sym, comma23Sym, comma34Sym, leftQuoteSym, rightQuoteSym: Symbol; aParenArg _ MakeArgument[$a, LIST[$aliasA, $aliasHot], normal]; leftParenSym _ MakeSymbol[$leftParen, NIL, normal, MathConstructors.MakePlainSym['(]]; rightParenSym _ MakeSymbol[$rightParen, NIL, normal, MathConstructors.MakePlainSym[')]]; aCurlyArg _ MakeArgument[$a, LIST[$aliasA, $aliasHot], normal]; leftCurlySym _ MakeSymbol[$leftCurly, NIL, normal, MathConstructors.MakePlainSym['{]]; rightCurlySym _ MakeSymbol[$rightCurly, NIL, normal, MathConstructors.MakePlainSym['}]]; aSquareArg _ MakeArgument[$a, LIST[$aliasA, $aliasHot], normal]; leftSquareSym _ MakeSymbol[$leftSquare, NIL, normal, MathConstructors.MakePlainSym['[]]; rightSquareSym _ MakeSymbol[$rightSquare, NIL, normal, MathConstructors.MakePlainSym[']]]; leftQuoteSym _ MakeSymbol[$leftSquare, NIL, normal, MathConstructors.MakePlainSym['']]; rightQuoteSym _ MakeSymbol[$rightSquare, NIL, normal, MathConstructors.MakePlainSym['']]; carArg _ MakeArgument[$car, LIST[$aliasA, $aliasHot], normal]; cdrArg _ MakeArgument[$cdr, LIST[$aliasB], normal]; commaSym _ MakeSymbol[$comma, NIL, normal, MathConstructors.MakeItalSym[',]]; listSpSym _ MakeSymbol[$space, LIST[$aliasSpace], normal, MathConstructors.MakeSpace[$thick]]; fArg _ MakeArgument[$f, LIST[$aliasA, $aliasHot], normal]; arg1 _ MakeArgument[$arg1, LIST[$aliasB], normal]; arg2 _ MakeArgument[$arg2, NIL, normal]; arg3 _ MakeArgument[$arg3, NIL, normal]; arg4 _ MakeArgument[$arg4, NIL, normal]; funLParenSym _ MakeSymbol[$leftParen, NIL, normal, MathConstructors.MakePlainSym['[]]; funRParenSym _ MakeSymbol[$rightParen, NIL, normal, MathConstructors.MakePlainSym[']]]; altFunLP _ MakeSymbol[$leftParen, NIL, normal, MathConstructors.MakeSpace[$null]]; altFunRP _ MakeSymbol[$rightParen, NIL, normal, MathConstructors.MakeSpace[$null]]; funSpaceSym _ MakeSymbol[$funSpace, LIST[$aliasSpace], normal, MathConstructors.MakeSpace[$medium]]; arg12SpaceSym _ MakeSymbol[$arg12Space, NIL, normal, MathConstructors.MakeSpace[$medium]]; arg23SpaceSym _ MakeSymbol[$arg23Space, NIL, normal, MathConstructors.MakeSpace[$medium]]; arg34SpaceSym _ MakeSymbol[$arg34Space, NIL, normal, MathConstructors.MakeSpace[$medium]]; comma12Sym _ MakeSymbol[$comma12, NIL, normal, MathConstructors.MakeItalSym[',]]; comma23Sym _ MakeSymbol[$comma23, NIL, normal, MathConstructors.MakeItalSym[',]]; comma34Sym _ MakeSymbol[$comma34, NIL, normal, MathConstructors.MakeItalSym[',]]; listClass _ MakeCompoundClass[$list, other, "a, b", LIST[carArg, cdrArg], LIST[commaSym, listSpSym], FixedSizeBoxRule, ListCompRule, "($car, $cdr)", "{$car, $cdr}"]; -- these are binary, not n-ary, lists nullaryFunctionClass _ MakeCompoundClass[$nullaryFunction, other, "function()", LIST[fArg], LIST[funLParenSym, funRParenSym, funSpaceSym], FixedSizeBoxRule, NullaryFunctionCompRule, "$f []", "$f ()", "$f []"]; unaryFunctionClass _ MakeCompoundClass[$unaryFunction, other, "function(arg)", LIST[fArg, arg1], LIST[funSpaceSym, funLParenSym, funRParenSym], UnaryFunctionBoxRule, UnaryFunctionCompRule, "$f [$arg1]", "$f ($arg1)", "$f [$arg1]"]; binaryFunctionClass _ MakeCompoundClass[$binaryFunction, other, "function(arg1, arg2)", LIST[fArg, arg1, arg2], LIST[funSpaceSym, funLParenSym, comma12Sym, arg12SpaceSym, funRParenSym], BinaryFunctionBoxRule, BinaryFunctionCompRule, "$f [$arg1, $arg2]", "$f ($arg1, $arg2)", "$f [$arg1, $arg2]"]; ternaryFunctionClass _ MakeCompoundClass[$ternaryFunction, other, "function(arg1, arg2, arg3)", LIST[fArg, arg1, arg2, arg3], LIST[funSpaceSym, funLParenSym, comma12Sym, arg12SpaceSym, comma23Sym, arg23SpaceSym, funRParenSym], TernaryFunctionBoxRule, TernaryFunctionCompRule, "$f [$arg1, $arg2, $arg3]", "$f ($arg1, $arg2, $arg3)", "$f [$arg1, $arg2, $arg3]"]; quaternaryFunctionClass _ MakeCompoundClass[$quaternaryFunction, other, "function(arg1, arg2, arg3, arg4)", LIST[fArg, arg1, arg2, arg3, arg4], LIST[funSpaceSym, funLParenSym, comma12Sym, arg12SpaceSym, comma23Sym, arg23SpaceSym, comma34Sym, arg34SpaceSym, funRParenSym], QuaternaryFunctionBoxRule, QuaternaryFunctionCompRule, "$f [$arg1, $arg2, $arg3, $arg4]", "$f ($arg1, $arg2, $arg3, $arg4)", "$f [$arg1, $arg2, $arg3, $arg4]"]; altFunctionClass _ MakeCompoundClass[$altFunction, other, "function arg", LIST[fArg, arg1], LIST[altFunLP, altFunRP, funSpaceSym], FixedSizeBoxRule, UnaryFunctionCompRule, "(function $f $arg1)"]; parenClass _ MakeCompoundClass[$paren, paren, "( a )", LIST[aParenArg], LIST[leftParenSym, rightParenSym], ParenBoxRule, ParenCompRule, "( $a )", "( $a )", "( $a )"]; curlyClass _ MakeCompoundClass[$curly, paren, "{ a }", LIST[aCurlyArg], LIST[leftCurlySym, rightCurlySym], CurlyBoxRule, CurlyCompRule, "{ $a }"]; squareClass _ MakeCompoundClass[$square, paren, "[ a ]", LIST[aSquareArg], LIST[leftSquareSym, rightSquareSym], SquareBoxRule, SquareCompRule, "[ $a ]"]; quoteClass _ MakeCompoundClass[$quote, paren, "' a", LIST[aSquareArg], LIST[leftQuoteSym, rightQuoteSym], SquareBoxRule, SquareCompRule, "quote($a)"]; MathDB.InstallCompoundClass[parenClass]; MathDB.AddOperator[parenClass, $List]; MathDB.InstallCompoundClass[curlyClass]; MathDB.AddOperator[curlyClass, $List]; MathDB.InstallCompoundClass[squareClass]; MathDB.AddOperator[squareClass, $List]; MathDB.InstallCompoundClass[quoteClass]; MathDB.AddOperator[quoteClass, $List]; MathDB.InstallCompoundClass[altFunctionClass]; MathDB.AddOperator[altFunctionClass, $List]; MathDB.InstallCompoundClass[nullaryFunctionClass]; MathDB.AddOperator[nullaryFunctionClass, $List]; MathDB.InstallCompoundClass[unaryFunctionClass]; MathDB.AddOperator[unaryFunctionClass, $List]; MathDB.InstallCompoundClass[binaryFunctionClass]; MathDB.AddOperator[binaryFunctionClass, $List]; MathDB.InstallCompoundClass[ternaryFunctionClass]; MathDB.AddOperator[ternaryFunctionClass, $List]; MathDB.InstallCompoundClass[quaternaryFunctionClass]; MathDB.AddOperator[quaternaryFunctionClass, $List]; }; InstallListClassesB: PROC [] ~ { assignmentClass: CompoundClass; assignmentClass _ MakeRelationClass[$assign, $assign, $lhs, $rhs, MathConstructors.MakePlainSym['\254], "a _ b", "$lhs _ $rhs", "$lhs := $rhs", "$lhs : $rhs"]; MathDB.InstallCompoundClass[assignmentClass]; MathDB.AddOperator[assignmentClass, $List]; }; InstallListClassesAA[]; InstallListClassesB[]; END. ώMathExprClassesList.mesa Carl Waldspurger, August 30, 1986 7:12:37 pm PDT Bier, November 20, 1986 2:02:38 pm PST Arnon, March 24, 1987 4:15:37 pm PST Mcisaac, July 8, 1987 1:05:10 pm PDT Type Abbreviations from Imported Interfaces Procedure Abbreviations from Imported Interfaces Constants Box Procs for Compound Expr Classes effects: Returns unaltered boxes (i.e. no resizing takes place) effects: Sizes boxes for expr of form ($paren $a) right and left parentheses must be as tall as expression "a" effects: Sizes boxes for expr of form ($curly $a) right and left curly brackets must be as tall as expression "a" effects: Sizes boxes for expr of form ($square $a) right and left square brackets must be as tall as expression "a" QuoteBoxRule: CompoundBoxProc ~ { effects: Sizes boxes for expr of form ($quote $a) leftSquareBox: BOX _ MathBox.GetBox[$leftQuote, boxes]; rightSquareBox: BOX _ MathBox.GetBox[$rightQuote, boxes]; aBox: BOX _ MathBox.GetBox[$a, boxes]; right and left square brackets must be as tall as expression "a" scaleFactor: REAL _ MAX[0.25, 1.1 * aBox.Height[] / leftSquareBox.Height[]]; leftSquareBox _ MathBox.Scale[leftSquareBox, [scaleFactor, scaleFactor]]; rightSquareBox _ MathBox.Scale[rightSquareBox, [scaleFactor, scaleFactor]]; RETURN[LIST[aBox, leftSquareBox, rightSquareBox]]; }; effects: Sizes boxes for expr of form ($f $funSpace $leftParen $arg1 $rightParen) should ENABLE noSuchBox parens must be as tall as arg effects: Sizes boxes for expr of form ($f $funSpace $leftParen $arg1 $comma12 $arg12Space $arg2 $rightParen) should ENABLE noSuchBox right and left parentheses must be as tall as max of arg heights; comma should also scale effects: Sizes boxes for expr of form ($f $funSpace $leftParen $arg1 $arg2 $arg3 $rightParen) should ENABLE noSuchBox right and left parentheses must be as tall as max of arg expressions effects: Sizes boxes for expr of form ($f $funSpace $leftParen $arg1 $arg2 $arg3 $$arg4 rightParen) should ENABLE noSuchBox right and left parentheses must be as tall as max of arg expressions Composition Procs for Compound Expr Classes effects: Composes layout for expr of form ($comma $car $cdr) with symbol $space. effects: Composes layout for expr of form ($f $funSpace $leftParen $rightParen) effects: Composes layout for expr of form ($f $funSpace $arg1 $leftParen $rightParen) effects: Composes layout for expr of form ($aliasUnaryOp $aliasA). effects: Composes layout for expr of form ($aliasBinOp $aliasA $aliasB) with symbols $aliasLeftSpace & $aliasRightSpace. set vertical offset depending on format classes of A & B arguments effects: Composes layout for expr of form ($aliasRelation $aliasLHS $aliasRHS) with symbols $aliasLeftSpace & $aliasRightSpace. set vertical offset depending on format classes of lhs & rhs arguments effects: Composes layout for expr of form ($paren $a) with symbols $leftParen and $rightParen effects: Composes layout for expr of form ($curly $a) with symbols $leftCurly and $rightCurly effects: Composes layout for expr of form ($square $a) with symbols $leftSquare and $rightSquare Class Constructors effects: Creates and returns standard unary operation compound class named "class". The alignment is "operation arg"; alignment is thru baselines. Both op, arg are of fixed size "normal". effects: Creates and returns standard relation compound class named "class". The alignment is "lhs relation rhs"; alignment is thru baselines. All of lhs, rhs, rel are of fixed size "normal". Signals & Errors Define & Install Expression Classes local declarations define info for "( a )" define info for "{ a }" define info for "[ a ]" define info for quote(a) define info for "$list $car $cdr" define info for functions (parens also used by complex) funLParenSym _ MakeSymbol[$leftParen, NIL, normal, MathConstructors.MakePlainSym['\050]]; funRParenSym _ MakeSymbol[$rightParen, NIL, normal, MathConstructors.MakePlainSym['\051]]; define compound classes others Register compound classes in user-friendly order *** 7/16/87 disable lists so Reduce list function treated as unknown func MathDB.InstallCompoundClass[listClass]; MathDB.AddOperator[listClass, $List]; *** local declarations assignmentClass, quoteClass: CompoundClass; relations quoteClass _ MakeUnaryOpClass[$quote, $quote, $a, MathConstructors.MakePlainSym[''], "quote a", "quote($a)"]; MathDB.InstallCompoundClass[quoteClass]; MathDB.AddOperator[quoteClass, $List]; Install Classes Defined in this Module Κ˜Jšœ™šœ0™0Icode™&K™$K™$—J˜J˜šΟk ˜ Kšœ ˜ Kšœ ˜ K˜K˜ K˜Kšœ˜Kšœ˜Kšœ˜Kšœ˜K˜—J˜šΟnœœœ˜#šœ˜&Jšœ˜—Jšœ˜J˜Jš˜—J˜headšž+™+Jšœœ œ˜Jšœœ œ˜Jšœœœ˜Jšœœ œ˜Jšœœ˜2Jšœœ˜2Jšœ œ˜*Jšœœ˜ Jšœœ˜J˜Jšœ œ˜#Jšœœ˜Jšœœ˜-Jšœ œ˜*Jšœœ˜—šž0™0Jšž œœœ œœœœ#˜lJ˜Jšž œœœ œœœœœ˜sJ˜Jšžœœœ)œœœœœaœœœ-˜——šž ™ Jšœ œ˜Jšœœ˜Jšœœ˜—šž#™#šžœ˜%Kšœ@™@Kšœ˜K˜—šž œ˜!Kšœ2™2K™Kšœœ%˜6Kšœœ&˜8Kšœœ˜&K˜Kšœ<™Kšœ!œ$˜IKšœ+œ?˜nKšœ-œ@˜qK˜Kšœ1œœM˜žK˜——šž™Kšœœœœ˜"—šž$™$šžœœ˜!K˜Kšœ™KšœΚ˜ΚKšœZ˜ZKšœ‘˜‘K˜Kšœ™Kšœœ˜?Kšœ&œ-˜VKšœ(œ-˜XK˜Kšœ™Kšœœ˜?Kšœ&œ-˜VKšœ(œ-˜XK˜Kšœ™Kšœœ˜@Kšœ(œ-˜XKšœ*œ-˜ZK˜Kšœ™KšœW˜WKšœY˜YK˜Kšœ!™!Kšœœ˜>Kšœœ˜3Kšœœ,˜MKšœœ;˜^K˜Kšœ7™7Kšœœ˜:Kšœœ˜2Kšœœ ˜(Kšœœ ˜(Kšœœ ˜(Kšœ&œ0™YKšœ'œ0™ZKšœ&œ-˜VKšœ'œ-˜WKšœ"œ-˜RKšœ#œ-˜SKšœ$œ<˜dKšœ(œ/˜ZKšœ(œ/˜ZKšœ(œ/˜ZKšœ"œ,˜QKšœ"œ,˜QKšœ"œ,˜QK˜K˜Kšœ™K™K˜Kšœ™Kšœ4œœXŸ%˜ΛKšœPœœq˜ΡKšœOœœ‚˜ηKšœXœœ΄˜¨Kšœ`œœζ˜θKšœlœ œ˜±KšœJœœc˜ΓKšœ7œ œ[˜§Kšœ7œ œG˜“Kšœ9œœK˜šKšœ5œœL˜—K˜K˜K™1K™K˜K˜(Kšœ&˜&Kšœ(˜(Kšœ&˜&Kšœ)˜)Kšœ'˜'K˜K™IK™'Kšœ%™%K™K™Kšœ(˜(Kšœ&˜&K˜.Kšœ,˜,Kšœ2˜2Kšœ0˜0Kšœ0˜0Kšœ.˜.Kšœ1˜1Kšœ/˜/Kšœ2˜2Kšœ0˜0Kšœ5˜5Kšœ3˜3K˜K˜K˜—šžœœ˜ K˜Kšœ™Kšœ˜Kšœ+™+K˜Kšœ ™ Kšœm™mKšœŸ˜ŸK˜K™Kšœ-˜-Kšœž œ˜+Kšœ(™(Kšœž œ™&K˜K˜——šž&™&K˜K˜—K˜šœ˜K˜—J˜J˜J˜—…—\FƒK