\documentclass[nocolor,memo]{j3}
\renewcommand{\hdate}{19 September 2004}
\renewcommand{\vers}{J3/04-390}
\usepackage{lineno}
\usepackage{longtable}
\usepackage{xr}
\externaldocument{007}
\input pdftest
\begin{document}
\vspace{-10pt}
\begin{tabbing}
Subject: \hspace*{0.25in}\=.ANDTHEN. and .ORELSE.\\
From: \>Van Snyder\\
Reference: \>03-258r1, section 2.8.2; 04-193, 04-192, 04-357, 04-363\\
\end{tabbing}
\pagewiselinenumbers
\leftlinenumbers
\linenumbers*
\section{Number}
TBD
\section{Title}
.ANDTHEN. and .ORELSE.
\section{Submitted By}
J3
\section{Status}
For consideration.
\section{Basic Functionality}
Provide \emph{and} and \emph{or} operators that are guaranteed to
short-circuit evaluation.
\section{Rationale}
The standard presently allows a processor to short-circuit evaluation of
logical expressions. For example, in {\tt A~.AND.~B}, the processor is
allowed not to evaluate {\tt B} if {\tt A} is false. It is sometimes
desirable, however, to \emph{require} that the processor not evaluate
{\tt B} if {\tt A} is false, as opposed simply to \emph{allowing} it not
to. Here's an example:
\hspace*{0.25in}{\tt if ( present(x) .and.~x /= 0 ) ...}
One can't \emph{depend} on the processor not trying to evaluate {\tt x /=
0} if {\tt x} is not present.
To support this desire, add an {\tt .ANDTHEN.} operator, the semantics of
which require the processor to evaluate the first operand first, and then
prohibit it from evaluating the second operand if the first is false.
The example becomes:
\hspace*{0.25in}{\tt if ( present(x) .andthen.~x /= 0 ) ...}
Similar considerations apply to the .OR. operator, leading to the desire
for an .ORELSE. operator, in which the second operand is prohibited to be
evaluated if the first is true.
These operators are, of course, even more useful elementally in WHERE
statements and constructs. For example
\hspace*{0.25in}{\tt where ( x > 0.0 .andthen.~log(x) < tol ) ...}
The semantical property of these operators that their second operand is
not evaluated if the first is false (true) could be provided by
conditional expressions (04-192) or a conditional-execution intrinsic
function (04-357), \emph{viz.} {\tt A .ANDTHEN.\ B} could be represented
{\tt A ? B :\ .FALSE.} or {\tt IF ( A, B, .FALSE.~)} and {\tt A .ORELSE.\
B} could be represented as {\tt A ? .TRUE.~:\ B} or {\tt IF ( A, .TRUE.,
B~)} . Thus, if the proposal for conditional expressions proceeds, this
proposal is somewhat redundant.
\section{Estimated Impact}
Minor. Estimated at meeting 169 to be at 4 on the JKR scale.
\section{Detailed Specification}
Provide \emph{and} and \emph{or} operators that are guaranteed not to
evaluate their second operand if the first operand is false (in the
\emph{and} case) or true (in the \emph{or} case). It is proposed that
these operators be spelt .ANDTHEN.\ and .ORELSE.
To facilitate converting between .AND.\ and .ANDTHEN., and between .OR.\
and .ORELSE., it would be useful if the precedences of the new operators
were immediately below .AND. and .OR. Since programs may already have
user-defined operators with the same spelling, it would be useful if the
precedence of the new operators were the same as the precedence of
user-defined operators. This can be resolved later.
\subsection{Suggested edits}
The following suggested edits illustrate the magnitude of the project.
They assume that the precedences of .ANDTHEN. and .ORELSE. are immediately
below .AND. and .OR., respectively. The size of the project would not
change substantially if the other decision were to prevail.
\sep\mgpar{26:25+}\bnfx{719$\frac12$}{andthen-op}{.ANDTHEN.}
\sep\mgpar{26:26+}\bnfx{720$\frac12$}{orelse-op}{.ORELSE.}
\sep\mgpar{44:14}[Insert ``and .ANDTHEN.'' after ``.AND'' and ``and
.ORELSE.'' after ``.OR.''.]
\sep\mgpar{120:5-6}\bnfx{714$\frac12$}{andthen-operand}{[
\si{andthen-operand} \si{and-op} ] \si{and-operand}}\\
\bnfx{715}{or-operand}{[ \si{or-operand} \si{andthen-op} ]
\si{andthen-operand}}\\
\bnfx{715$\frac12$}{orelse-operand}{[ \si{orelse-operand} \si{or-op} ]
\si{or-operand}}\\
\bnfx{716}{equiv-operand}{[ \si{equiv-operand} \si{orelse-op} ]
\si{orelse-operand}}
\sep\mgpar{120:9+}\bnfx{719$\frac12$}{andthen-op}{.ANDTHEN.}
\sep\mgpar{120:10+}\bnfx{720$\frac12$}{orelse-op}{.ORELSE.}
\sep\mgpar{121:7+17}[Add ``, .ANDTHEN.'' after ``.AND.'' and ``, .ORELSE.''
after ``.OR.'' in the first column of Table 7.1.]
\sep\mgpar{121:20}[Add ``, .ANDTHEN.'' after ``.AND.'' and ``, .ORELSE.''
after ``.OR.''.]
\sep\mgpar{132:4}[Replace ``Once'' by ``For the .AND., .OR., .EQV., and
.NEQV. operators, once''.]
\sep\mgpar{132:8- New \P}For the .ANDTHEN. operator the second operand
shall not be evaluated if the first is false. For the .ORELSE. operator,
the second operand shall not be evaluated if the first is true.
Otherwise, once the interpretation of an expression has been established
in accordance with the rules given in \ref{D7:Logical intrinsic
operations}, the processor may evaluate any other expression that is
logically equivalent, provided that the integrity of parentheses in any
expression is not violated.
\sep\mgpar{135:28+4,5+}[Insert two new rows in Table 7.5:]
\begin{longtable}{|lllp{1.9in}|}
.ANDTHEN. &
Logical conjunction&
$x_1$ .ANDTHEN. $x_2$&
True if $x_1$ and $x_2$ are both true, but $x_2$ shall not be
evaluated if $x_1$ is false\\
.ORELSE. &
Logical inclusive disjunction&
$x_1$ .ORELSE. $x_2$&
True if either $x_1$ or $x_2$ is true, but $x_2$ shall not be
evaluated if $x_1$ is true\\
\end{longtable}
\sep\mgpar{136:1+2+}[In the heading of Table 7.6, Add ``$x_1$ .ANDTHEN.
$x_2$'' under ``$x_1$ .AND. $x_2$'' and ``$x_1$ .ORELSE. $x_2$'' under
``$x_1$ .OR. $x_2$''.]
\label{lastpage}
\sep\mgpar{136:5+13}[In Table 7.7, replace the .OR. row]
\begin{longtable}{|ccc|}
Logical & .ANDTHEN. & $\cdot$\\
Logical & .OR. & $\cdot$\\
Logical & .ORELSE. & $\cdot$\\
\end{longtable}
%\section{History}
\end{document}