macrakis@harvard.UUCP (Stavros Macrakis) (03/10/86)
Frank Adams (franka@mmintl.UUCP) writes that he often uses a control
structure which is hard to code using standard primitives. I show
here that (1) his particular case can straightforwardly be programmed
and (2) that the general problem of which his is a special case cannot
be handled by any of the standard techniques.
His particular case can, in fact, easily be written (in Ada for example) as:
Av := A; -- boolean A
if Av then X; end if; -- Av only needed in special case
if (Av and then B) then Y; -- where A and X interfere, or
else Z; -- A is expensive
end if;
His proposed solution is somewhat neater, but is it worth the (very)
special case?:
if (A) then X;
and if (B) then Y;
else Z;
After all, in general, control structures of the form:
[ <boolean function> => clause;
<boolean function> => clause;
... ]
cannot be written -- not in flowcharts/goto programs, not in
if-then-else, not even in if-and-if -- in such a way that boolean
variables are not repeated. `Decision tables' do clean up this
situation somewhat.
Adams also points out that some languages do not provide for
short-circuit boolean operators (or leave the semantics of boolean
operators up to the implementation!). This is, as far as I can tell,
an entirely separate problem.
-s