RatIntervalsImpl.mesa
Last Edited by: Arnon, July 19, 1985 2:54:46 pm PDT
DIRECTORY
Rope,
IO,
BigRats,
RatIntervals;
RatIntervalsImpl: CEDAR PROGRAM
IMPORTS Rope, IO, BigRats
EXPORTS RatIntervals
= BEGIN OPEN RN: BigRats, RatIntervals;
ReadRatInterval: PUBLIC PROC [in: IO.STREAM] RETURNS [out: RatInterval] ~ {
puncChar: CHAR;
leftEndPoint, rightEndPoint: RN.BigRat;
[]← in.SkipWhitespace[];
puncChar ← in.GetChar[ ];
IF puncChar # '( THEN ERROR;
leftEndPoint ← NARROW[ RN.BigRats.class.read[in] ];
[]← in.SkipWhitespace[];
puncChar ← in.GetChar[ ];
IF puncChar # ', THEN ERROR;
rightEndPoint ← NARROW[ RN.BigRats.class.read[in] ];
[]← 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, RN.BigRats.class.toRope[in.leftEndPoint], " , "];
out ← Rope.Cat[out, RN.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.