MergeVariableSequences:
PUBLIC
AC.BinaryOp ~ {
All variables of firstArg that do not occur in secondArg are placed at left (low) end of result; all variables Variables X and Y may occur in different order in the two args; no note is made of this; they will occur in result in the order they had in secondArg.
firstSeqData: SEQ.SequenceData ← NARROW[firstArg.data];
secondSeqData: SEQ.SequenceData ← NARROW[secondArg.data];
firstStructureData: SEQ.SequenceStructureData ← NARROW[firstArg.class.data];
secondStructureData: SEQ.SequenceStructureData ← NARROW[firstArg.class.data];
firstElementStructure: Object ← firstStructureData.elementStructure;
secondElementStructure: Object ← firstStructureData.elementStructure;
intIndex: Ints.Int;
lowVars, lowVarsPointer: LIST OF VARS.Variable;
lowVarSeq: VariableSequence ← NIL;
IF NOT AC.StructureEqual[firstElementStructure, secondElementStructure] THEN TypeError[];
FOR i:
INT
IN [1..firstSeqData.lengthPlus1)
DO
intIndex ← SEQ.Find[secondArg, firstSeqData[i] ];
IF intIndex=
NIL
THEN {
IF lowVars #
NIL
THEN
lowVarsPointer ← lowVarsPointer.rest ← LIST[firstSeqData[i] ]
ELSE
lowVars ← lowVarsPointer ← LIST[firstSeqData[i] ];
};
ENDLOOP;
IF lowVars # NIL THEN lowVarSeq ← SEQ.MakeSequence[lowVars, VariableSequences];
RETURN[SEQ.Concatenate[lowVarSeq, secondArg] ];
};
NewMainVariable:
PUBLIC
AC.BinaryOp ~ {
firstArg is a VariableSequence, secondArg is a Variable that may or may not occur in firstArg. result is firstArg with reordered variables so that secondArg is new main variable. Order of other variables is preserved
pos: Ints.Int ← SEQ.Find[firstArg, secondArg];
delSeq: Object;
IF pos#
NIL
THEN
delSeq ← SEQ.Delete[firstArg, pos]
RETURN[ SEQ.Append[delSeq, secondArg] ];
};