Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!samsung!think.com!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!sics.se!dan From: dan@sics.se (Dan Sahlin) Newsgroups: comp.lang.prolog Subject: Re: '->' operator Message-ID: <1991Jan10.103521.2278@sics.se> Date: 10 Jan 91 10:35:21 GMT References: <291@valverde.cs.utexas.edu> <1991Jan4.030918.24996@athena.cs.uga.edu> <1991Jan4.061142.26941@athena.cs.uga.edu> <6402@munnari.oz.au> Sender: news@sics.se Organization: SICS, Swedish Inst. of Computer Science Lines: 35 Jeff Schultz wrote: >I find the definition of (C -> T) as (once(C), T) much less useful in >practice than the if-like one, but there's no question that it's the >standard behaviour. Sad, really. I agree, and would add that not only is the semantics bad, but also the syntax of if-then-else, especially if you do program transformations. For instance, "A;(B;C)" is not equivalent to "(A;B);C" in Prolog, due to the poor syntax of if-then-else. Let A be "(Test->Then)" and you see why. Another example, "true,D" is not always the same as "D", if "D" is "(Test->Then)". The expression "(true,(Test->Then));E" is not the same as "(Test->Then);E". It really becomes complicated if you have a clause of the form p(G,X) :- G; X=2. So what happens if you call "p((true->X=1),X)"? Instead just getting X=1, you also get X=2 on backtracking, as the clause when read in is first converted into p(G,X) :- call(G); X=2. On the other hand, not all meta-goals G are converted into call(G), as in the clause p2(G,X) :- call((G; X=2)). The call "p2((true->X=1),X)" will only return the answer X=1. The above examples are run in compiled and interpreted SICStus Prolog, but many other Prolog systems show the same behavior. If I am correctly informed, the forthcoming Prolog standard will keep this syntax and semantics of if-then-else. /Dan Sahlin