[net.lang.prolog] bug in CProlog grammar rules

tombl@ogcvax.UUCP (Tom Blenko) (07/11/83)

There is a bug in the CProlog grammar rules. Translation of expressions
of the following form may be affected:

	(expr1 ; expr2)

The current rules produce code which may incorrectly bind the return
que for some instances of user code. For example, the expression

	( funct(arg1,...,argn) ; {expr1} )

is translated to produce

	funct(arg1,...,argn,Input,Output)

for the left member, which is correct. Translation of the right member
returns expr1, also correct, but has the side effect of binding its
input que to its output que. These happen also to be the input and
output ques for the expression as a whole, so the left member
translation effectively becomes

	funct(arg1,...,argn,Input,Input)

which is incorrect.

The bug fix is straightforward, and should be applied to
~prolog/pl/grammar:

30,32c30,32
< $t_rp((T;R),S,SR,(Tt;Rt)) :- !,	/* distributed code */
<    $t_rp(T,S,SR,Tt),
<    $t_rp(R,S,SR,Rt).
---
> $t_rp((T;R),S,SR,(Tt,SR=SR1;Rt,SR=SR2)) :- !, /* modified code */
>    $t_rp(T,S,SR1,Tt),
>    $t_rp(R,S,SR2,Rt).

I'd be interested in seeing a better solution, if someone should come up
with one.

	Tom Blenko
	decvax!tektronix!ogcvax!metheus!tombl
	ucbvax!tektronix!ogcvax!metheus!tombl