next up previous contents
Next: Loops Up: Expressions Previous: Dispatch   Contents


Conditionals

A conditional has the form

if <expr> then <expr> else <expr> fi

The semantics of conditionals is standard. The predicate is evaluated first. If the predicate is true, then the then branch is evaluated. If the predicate is false, then the else branch is evaluated. The value of the conditional is the value of the evaluated branch.

The predicate must have static type Bool. The branches may have any static types. To specify the static type of the conditional, we define an operation $\sqcup$ (pronounced ``join'') on types as follows. Let A,B,D be any types other than SELF_TYPE. The least type of a set of types means the least element with respect to the conformance relation $\leq$.

\begin{displaymath}
\begin{array}{rcl}
\tt A \sqcup B & = & \tt\mbox {\rm the le...
...\tt SELF\_TYPE}_D \sqcup A & = & \tt D \sqcup A \\
\end{array}\end{displaymath}

Let T and F be the static types of the branches of the conditional. Then the static type of the conditional is $\tt T \sqcup F$. (think: Walk towards Object from each of T and F until the paths meet.)