% Copyright The Numerical Algorithms Group Limited 1991.
% All rights reserved

\begin{page}{PrefixEval}{Example of Standard Evaluation}
\beginscroll
We illustrate the general evaluation of {\em op a} for some
prefix operator {\em op} and operand {\em a}
by the example: {\em cos(2)}.
The evaluation steps are as follows:
\vspace{1}\newline
1.\tab{3}{\em a} evaluates to a value of some type.
\newline\tab{3}{\em Example:} {\em 2} evaluates to {\em 2} of type \spadtype{Integer}
\newline
2.\tab{3}\Language{} then chooses a function {\em op} based on the type of {\em a}.
\newline\tab{3}{\em Example:} The function {\em cos:} \spadtype{Float} {\em ->}
\spadtype{Float} is chosen.
\newline
3.\tab{3}If the argument type of the function is different from that of {\em a},
then the system coerces
%\downlink{coerces}{Coercion}
the value of {\em a} to the
argument type.
\newline\tab{3}{\em Example:} The integer {\em 2} is coerced to the float {\em 2.0}.
\newline
4.\tab{3}The function is then applied to the value of {\em a} to produce the value
for {\em op a}.
\newline\tab{3}{\em Example:} The function {\em cos} is applied to {\em 2.0}.
\vspace{1}\newline
Try it:
\example{cos(2)}
\endscroll
\autobuttons\end{page}

\begin{page}{InfixEval}{Example of Standard Evaluation}
\beginscroll
We illustrate the general evaluation of {\em a op b} for some
infix operator {\em op} with operands {\em a} and {\em b}
by the example: {\em 2 + 3.4}.
The evaluation steps are as follows:
\vspace{1}\newline
1.\tab{3}{\em a} and {\em b} are evaluated, each producing a value and a type.
\newline\tab{3}{\em Example:} {\em 2} evaluates to {\em 2} of type \spadtype{Integer};
{\em 3.4} evaluates to {\em 3.4} of type \spadtype{Float}.
\vspace{1}\newline
2.\tab{3}\Language{} then chooses a function {\em op} based on the types of {\em a} and {\em b}.
\newline\tab{3}{\em Example:} The function {\em +: (D,D) -> D}
is chosen requiring a common type {\em D} for both arguments to {\em +}.
An operation called {\em resolve} determines the `smallest common type' \spadtype{Float}.
\vspace{1}\newline
3.\tab{3}If the argument types for the function are different from
those of {\em a} and {\em b},
then the system coerces
%\downlink{coerces}{Coercion}
the values to the argument types.
\newline\tab{3}{\em Example:} The integer {\em 2} is coerced to the float {\em 2.0}.
\vspace{1}\newline
4.\tab{3}The function is then applied to the values of {\em a} and {\em b}
to produce the value for {\em a op b}.
\newline\tab{3}{\em Example:} The function {\em +: (D,D) -> D}, where
{\em D} = \spadtype{Float} is applied to {\em 2.0} and {\em 3.4} to produce {\em 5.4}.
\vspace{1}\newline
Try it:
\example{2 + 3.4}
\endscroll
\autobuttons\end{page}
