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
DIRECTORY
MathExpr,
MathRules,
MathDB,
MathTypes,
MathBox,
Imager,
Rope,
Vector,
MathConstructors;
MathExprClassesList: CEDAR PROGRAM
IMPORTS MathBox, MathRules, MathExpr,
MathDB, MathConstructors
~
BEGIN
Type Abbreviations from Imported Interfaces
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;
Procedure Abbreviations from Imported Interfaces
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: ROPENIL] RETURNS[CompoundClass] ~ MathExpr.MakeCompoundClass;
Constants
smallGap: REAL = 0.05;
medGap: REAL = 0.10;
bigGap: REAL = 0.25;
Box Procs for Compound Expr Classes
FixedSizeBoxRule: CompoundBoxProc ~ {
effects: Returns unaltered boxes (i.e. no resizing takes place)
RETURN[boxes];
};
ParenBoxRule: CompoundBoxProc ~ {
effects: Sizes boxes for expr of form ($paren $a)
leftParenBox: BOX ← MathBox.GetBox[$leftParen, boxes];
rightParenBox: BOX ← MathBox.GetBox[$rightParen, boxes];
aBox: BOX ← MathBox.GetBox[$a, boxes];
right and left parentheses must be as tall as expression "a"
scaleFactor: REALMAX[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 ~ {
effects: Sizes boxes for expr of form ($curly $a)
leftCurlyBox: BOX ← MathBox.GetBox[$leftCurly, boxes];
rightCurlyBox: BOX ← MathBox.GetBox[$rightCurly, boxes];
aBox: BOX ← MathBox.GetBox[$a, boxes];
right and left curly brackets must be as tall as expression "a"
scaleFactor: REALMAX[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 ~ {
effects: Sizes boxes for expr of form ($square $a)
leftSquareBox: BOX ← MathBox.GetBox[$leftSquare, boxes];
rightSquareBox: BOX ← MathBox.GetBox[$rightSquare, boxes];
aBox: BOX ← MathBox.GetBox[$a, boxes];
right and left square brackets must be as tall as expression "a"
scaleFactor: REALMAX[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]];
};
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: REALMAX[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 ~ {
effects: Sizes boxes for expr of form ($f $funSpace $leftParen $arg1 $rightParen)
should ENABLE noSuchBox
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];
parens must be as tall as arg
scaleFactor: REALMAX[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 ~ {
effects: Sizes boxes for expr of form ($f $funSpace $leftParen $arg1 $comma12 $arg12Space $arg2 $rightParen)
should ENABLE noSuchBox
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];
right and left parentheses must be as tall as max of arg heights; comma should also scale
scaleFactor: REALMAX[
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 ~ {
effects: Sizes boxes for expr of form ($f $funSpace $leftParen $arg1 $arg2 $arg3 $rightParen)
should ENABLE noSuchBox
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];
right and left parentheses must be as tall as max of arg expressions
scaleFactor: REALMAX[
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 ~ {
effects: Sizes boxes for expr of form ($f $funSpace $leftParen $arg1 $arg2 $arg3 $$arg4 rightParen)
should ENABLE noSuchBox
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];
right and left parentheses must be as tall as max of arg expressions
scaleFactor: REALMAX[
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] ];
};
Composition Procs for Compound Expr Classes
ListCompRule: CompositionProc ~ {
effects: Composes layout for expr of form ($comma $car $cdr) with symbol $space.
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 ~ {
effects: Composes layout for expr of form ($f $funSpace $leftParen $rightParen)
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 ~ {
effects: Composes layout for expr of form ($f $funSpace $arg1 $leftParen $rightParen)
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 ~ {
effects: Composes layout for expr of form ($aliasUnaryOp $aliasA).
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 ~ {
effects: Composes layout for expr of form ($aliasBinOp $aliasA $aliasB) with
symbols $aliasLeftSpace & $aliasRightSpace.
tempBox: BOX;
tempBoxes: LIST OF BOX;
leftVertOffsetA, leftVertOffsetOp, rightVertOffsetB, rightVertOffsetOp: Offset;
alignments: LIST OF Alignment2D;
set vertical offset depending on format classes of A & B arguments
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 ~ {
effects: Composes layout for expr of form ($aliasRelation $aliasLHS $aliasRHS) with
symbols $aliasLeftSpace & $aliasRightSpace.
tempBox: BOX;
tempBoxes: LIST OF BOX;
leftVertOffsetLHS, leftVertOffsetRel, rightVertOffsetRHS, rightVertOffsetRel: Offset;
alignments: LIST OF Alignment2D;
set vertical offset depending on format classes of lhs & rhs arguments
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 ~ {
effects: Composes layout for expr of form ($paren $a) with symbols
$leftParen and $rightParen
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 ~ {
effects: Composes layout for expr of form ($curly $a) with symbols
$leftCurly and $rightCurly
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 ~ {
effects: Composes layout for expr of form ($square $a) with symbols
$leftSquare and $rightSquare
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];
};
Class Constructors
MakeUnaryOpClass: PUBLIC PROC[class, op, arg: ATOM, operation: EXPR, description: ROPE, cvtAS, cvtReduce, cvtSMP, cvtOther: ROPENIL] RETURNS[CompoundClass] ~ {
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".
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: ROPENIL] RETURNS[CompoundClass] ~ {
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".
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]];
};
Signals & Errors
wrongBoxType: PUBLIC ERROR = CODE;
Define & Install Expression Classes
InstallListClassesAA: PROC [] ~ {
local declarations
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;
define info for "( a )"
aParenArg ← MakeArgument[$a, LIST[$aliasA, $aliasHot], normal];
leftParenSym ← MakeSymbol[$leftParen, NIL, normal, MathConstructors.MakePlainSym['(]];
rightParenSym ← MakeSymbol[$rightParen, NIL, normal, MathConstructors.MakePlainSym[')]];
define info for "{ a }"
aCurlyArg ← MakeArgument[$a, LIST[$aliasA, $aliasHot], normal];
leftCurlySym ← MakeSymbol[$leftCurly, NIL, normal, MathConstructors.MakePlainSym['{]];
rightCurlySym ← MakeSymbol[$rightCurly, NIL, normal, MathConstructors.MakePlainSym['}]];
define info for "[ a ]"
aSquareArg ← MakeArgument[$a, LIST[$aliasA, $aliasHot], normal];
leftSquareSym ← MakeSymbol[$leftSquare, NIL, normal, MathConstructors.MakePlainSym['[]];
rightSquareSym ← MakeSymbol[$rightSquare, NIL, normal, MathConstructors.MakePlainSym[']]];
define info for quote(a)
leftQuoteSym ← MakeSymbol[$leftSquare, NIL, normal, MathConstructors.MakePlainSym['']];
rightQuoteSym ← MakeSymbol[$rightSquare, NIL, normal, MathConstructors.MakePlainSym['']];
define info for "$list $car $cdr"
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]];
define info for functions (parens also used by complex)
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['\050]];
funRParenSym ← MakeSymbol[$rightParen, NIL, normal, MathConstructors.MakePlainSym['\051]];
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[',]];
define compound classes
others
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)"];
Register compound classes in user-friendly order
MathDB.InstallCompoundClass[parenClass];
MathDB.AddOperator[parenClass, $List];
MathDB.InstallCompoundClass[curlyClass];
MathDB.AddOperator[curlyClass, $List];
MathDB.InstallCompoundClass[squareClass];
MathDB.AddOperator[squareClass, $List];
*** 7/16/87 disable lists so Reduce list function treated as unknown func
MathDB.InstallCompoundClass[listClass];
MathDB.AddOperator[listClass, $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 [] ~ {
local declarations
assignmentClass: CompoundClass;
assignmentClass, quoteClass: CompoundClass;
relations
quoteClass ← MakeUnaryOpClass[$quote, $quote, $a, MathConstructors.MakePlainSym[''], "quote a", "quote($a)"];
assignmentClass ← MakeRelationClass[$assign, $assign, $lhs, $rhs, MathConstructors.MakePlainSym['\254], "a ← b", "$lhs ← $rhs", "$lhs := $rhs", "$lhs : $rhs"];
MathDB.InstallCompoundClass[assignmentClass];
MathDB.AddOperator[assignmentClass, $List];
MathDB.InstallCompoundClass[quoteClass];
MathDB.AddOperator[quoteClass, $List];
};
Install Classes Defined in this Module
InstallListClassesAA[];
InstallListClassesB[];
END.