RatIntervalsImpl.mesa
Last Edited by: Arnon, July 19, 1985 2:54:46 pm PDT
DIRECTORY
BigRats,
AlgebraClasses,
Points,
RatIntervals;
RatIntervalsImpl: CEDAR PROGRAM
IMPORTS BigRats, Points
EXPORTS RatIntervals
= BEGIN OPEN BR: BigRats, RatIntervals;
RatIntervals: PUBLIC AlgebraClasses.Structure ← Points.MakePointStructure[BigRats.BigRats, 2];
ReadRatInterval: PUBLIC PROC [in: IO.STREAM] RETURNS [out: RatInterval] ~ {
puncChar: CHAR;
leftEndPoint, rightEndPoint: BR.BigRat;
[]← in.SkipWhitespace[];
puncChar ← in.GetChar[ ];
IF puncChar # '( THEN ERROR;
leftEndPoint ← NARROW[ BR.BigRats.class.read[in, BR.BigRats] ];
[]← in.SkipWhitespace[];
puncChar ← in.GetChar[ ];
IF puncChar # ', THEN ERROR;
rightEndPoint ← NARROW[ BR.BigRats.class.read[in, BR.BigRats] ];
[]← in.SkipWhitespace[];
puncChar ← in.GetChar[ ];
IF puncChar # ') THEN ERROR;
RETURN[NEW[RatIntervalRec ← [leftEndPoint, rightEndPoint] ] ];
};
RatIntervalFromRope: PUBLIC PROC [in: Rope.ROPE] RETURNS [out: RatInterval] = {
stream: IO.STREAMIO.RIS[in];
out ← ReadRatInterval[stream];
};
RatIntervalToRope: PUBLIC PROC [in: RatInterval, showDenomOne: BOOLFALSE] RETURNS [out: Rope.ROPE] ~ {
out ← "( ";
out ← Rope.Cat[out, BR.BigRats.class.toRope[in.leftEndPoint], " , "];
out ← Rope.Cat[out, BR.BigRats.class.toRope[in.rightEndPoint], " )"];
};
WriteRatInterval: PUBLIC PROC [in: RatInterval, out: IO.STREAM, showDenomOne: BOOLFALSE] ~ {
ratIntRope: Rope.ROPE ← RatIntervalToRope[in, showDenomOne];
out.PutF["%g\n", IO.rope[ratIntRope] ];
};
END.