ReadVariableSeq:
PUBLIC
PROC [in:
IO.
STREAM]
RETURNS [V: VariableSeq] ~ {
puncChar: CHAR;
nextVar: Rope.ROPE;
length: NAT ← 0;
ReadVLFail: PUBLIC ERROR [subclass: ATOM ← $Unspecified] = CODE;
VList, VListTail: LIST OF Rope.ROPE ← NIL;
[]← in.SkipWhitespace[];
puncChar ← in.GetChar[ ];
[]← in.SkipWhitespace[];
IF puncChar # '( THEN ReadVLFail[$LeftParenExpected];
WHILE puncChar # ')
DO
nextVar ← in.GetID[];
length ← length + 1;
[]← in.SkipWhitespace[];
IF VList=
NIL
THEN VList ← VListTail ←
LIST[nextVar]
ELSE
{ VListTail.rest ← LIST[nextVar]; VListTail ← VListTail.rest };
puncChar ← in.GetChar[];
[]← in.SkipWhitespace[];
IF puncChar # ') THEN IF puncChar # ', THEN ReadVLFail[$CommaExpected];
ENDLOOP;
V ← NEW[VariableSeqRec[length]];
FOR i:
NAT
IN [1..length]
DO
V[i] ← VList.first;
VList ← VList.rest;
ENDLOOP;
};
VariableSeqFromRope:
PUBLIC
PROC [in: Rope.
ROPE]
RETURNS [V: VariableSeq]={
VSStream: IO.STREAM ← IO.RIS[in];
RETURN[ ReadVariableSeq[ VSStream ] ];
};
VariableSeqToRope:
PUBLIC
PROC [V: VariableSeq]
RETURNS [out: Rope.
ROPE]={
out ← "(";
FOR i:
NAT
IN [1..V.lengthPlus1)
DO
out ← Rope.Concat[ out, V[i] ];
IF i < V.lengthPlus1 - 1 THEN out ← Rope.Concat[ out, "," ];
ENDLOOP;
out ← Rope.Concat[ out, ")" ];
};
WriteVariableSeq:
PUBLIC
PROC [V: VariableSeq, out:
IO.
STREAM] = {
Write in a reasonable format
VSRope: Rope.ROPE ← VariableSeqToRope[V];
out.PutF["\n %g \n", IO.rope[VSRope] ];
};