Sequences.mesa
Last Edited by: Arnon, May 3, 1986 3:53:47 pm PDT
Variable-length sequences of elements of some elementStructure.
DIRECTORY
Rope,
IO,
AlgebraClasses;
Sequences: CEDAR DEFINITIONS
~ BEGIN OPEN Rope, AC: AlgebraClasses;
Sequence Representation
Sequence: TYPE = AC.Object;
SequenceData: TYPE = REF SequenceDataRec;
SequenceDataRec: TYPE = RECORD [
SEQUENCE lengthPlus1:[1..65534] OF AC.Object
];
An empty sequence is represented with non-NIL data field consisting of a SequenceDataRec of length 0.
Instance Data for Sequence Structures
SequenceStructureData: TYPE = REF SequenceStructureDataRec;
SequenceStructureDataRec: TYPE = RECORD [
row: BOOLTRUE,
elementStructure: AC.Object
];
Sequence Structure Ops
MakeSequenceStructure: AC.SequenceStructureConstructor;
PrintName: AC.ToRopeOp;
ShortPrintName: AC.ToRopeOp;
ElementStructure: AC.UnaryOp;
Conversion and IO
Recast: AC.BinaryOp;
CanRecast: AC.BinaryPredicate;
ToExpr: AC.ToExprOp;
LegalFirstChar: AC.LegalFirstCharOp;
Read: AC.ReadOp;
FromRope: AC.FromRopeOp;
ToRope: AC.ToRopeOp;
Write: AC.WriteOp;
Constructor
MakeSequence: AC.ListImbedOp;
Attempts to recast supplied elements into elementStructure.
If data = NIL then returns a Sequence whose SequenceDataRec is of length 0.
Selection
Select: AC.BinaryOp;
firstArg is a Sequence, secondArg is an Ints.Int specifying position to select. Returns NIL if can't do.
First: AC.UnaryOp;
firstArg = Sequence, return first element. Return NIL if empty.
Last: AC.UnaryOp;
firstArg = Sequence, return last element. Return NIL if empty.
Length: AC.ElementRankOp;
Predicates
IsSubset: AC.BinaryPredicate;
firstArg and secondArg are Sequences. Returns TRUE if firstArg is a subset of secondArg. Returns FALSE if args have different elementStructures.
IsSubsequence: AC.BinaryPredicate;
firstArg and secondArg are Sequences. Returns TRUE if firstArg is a subsequence of secondArg. Returns FALSE if args have different elementStructures.
Operations
Equal: AC.BinaryPredicate;
Prepend: AC.BinaryOp;
firstArg = Sequence, secondArg = new Item. Place secondArg at the beginning of firstArg. secondArg must belong to firstArg's elementStructure.
Append: AC.BinaryOp;
firstArg = Sequence, secondArg = new Item. Place secondArg at the end of firstArg. secondArg must belong to firstArg's elementStructure.
Insert: AC.TernaryOp;
firstArg is a Sequence, secondArg is an Ints.Int specifying position after which to insert new item, thirdArg is new item. secondArg = 0 means insert at beginning, secondArg = i means insert after ith element of sequence. thirdArg must belong to firstArg's elementStructure.
Error if secondArg > Length[firstArg].
Delete: AC.BinaryOp;
firstArg is a Sequence, secondArg is a positive Ints.Int specifying position to delete.
Error if secondArg<1 OR secondArg > Length[firstArg].
DeleteLast: AC.UnaryOp;
firstArg is a Sequence. If length = 0, noOp.
Find: AC.BinaryOp;
firstArg is a Sequence, secondArg is an element of the Sequence's elementStructure. Returns an Ints.Int giving position of secondArg in firstArg if found, else returns NIL
Concatenate: AC.BinaryOp;
Concatenate two Sequences. Must have same elementStructure.
MapUnaryElementOp: AC.BinaryMixedOp;
firstArg is a Sequence, secondArg is a unary Method (e.g. UnaryOp, UnaryPredicate) on its elementStructure, result is Sequence of results of applications of the unary operation to the elements of firstArg.
MapBinaryElementOp: AC.TernaryMixedOp;
firstArg and secondArg are Sequences over the same elementStructure, and of the same length. thirdArg is a binary Method (e.g. BinaryOp, BinaryPredicate) on elementStructure. The result is a Sequence of the results of the application of the binary operation to corresponding pairs of elements of firstArg and secondArg.
END.