INTERFACEA JunoValue.T represents a Juno value. A value in Juno is either nil, a real number, a text string, or a pair of values.JunoValue ;
This interface also defines the procedure Unparse
to pretty-print a value
to a Wr.T
, and the procedure Equal
to determine if two Juno values are
equal.
IMPORT Wr, Word, Formatter, Real AS R; TYPE T = REFANY; (* Null | TEXT | REF Real | REF Pair *) Null <: T; Pair = RECORD car, cdr: T END;The following three declarations control the precision of Juno-2's calculations. Currently they are set to use single precision.
TYPE Real = REAL; CONST Zero = 0.0; VAR HalfEps: Real;
Zero
and HalfEps
are the zero and the relative error for type
Real
. That is, the difference between a real number x
and
the result of rounding it to a Real
is at most HalfEps*x
.
HalfEps
is initialized in the body of the JunoValue
module.
VAR (*CONST*) Nil: Null;The Juno value
NIL
is stored uniquely in the global variable Nil
.
CONST Prec: CARDINAL = R.MaxSignifDigits - 1; PROCEDURE Unparse(wr: Wr.T; x: T; width: CARDINAL := 75; prec := Prec) RAISES {Wr.Failure};
Pretty-print the valuex
towr
to a line width ofwidth
. Real numbers are unparsed toprec
digits of precision.
PROCEDURE UnparseToFmt(f: Formatter.T; x: T; prec := Prec) RAISES {Wr.Failure};
Pretty-print the valuex
to the formatterf
. The formatter is neither flushed nor closed by this procedure. Real numbers are unparsed toprec
digits of precision.
PROCEDURE Equal(READONLY x, y: T): BOOLEAN; PROCEDURE Hash(READONLY k: T): Word.T;
Equality and hash procedures on Juno values.
The following procedures return the sine, cosine, tangent, arc-sine, arc-cosine, arc-tangent, exponential, natural logarithm, and square root of the JunoValue.Real
x
. Ln
returns NaN if x <= 0.0
, and Sqrt
returns
NAN if x < 0.0
.
PROCEDURE Sin(x: Real): Real; PROCEDURE Cos(x: Real): Real; PROCEDURE Tan(x: Real): Real; PROCEDURE Asin(x: Real): Real; PROCEDURE Acos(x: Real): Real; PROCEDURE Atan(y, x: Real): Real; (* arc-tangent of "y/x" *) PROCEDURE Exp(x: Real): Real; PROCEDURE Ln(x: Real): Real; PROCEDURE Sqrt(x: Real): Real; PROCEDURE RefReal(x: Real): REF Real;
Return aREF Real
with valuex
.
PROCEDURE NewPoint(x, y: Real): REF Pair;
Return a pair of the numeric valuesx
andy
.
PROCEDURE ListFromVals(READONLY v: ARRAY OF T): T;
Return the list containing the values of v
.
PROCEDURE IsList(v: T): BOOLEAN;
RETURN TRUE iff v
is a (non-empty) list.
END JunoValue.