Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!mcvax!enea!zyx!bd From: bd@zyx.UUCP Newsgroups: comp.lang.prolog Subject: Re: Prolog control structures Message-ID: <397@zyx.UUCP> Date: Fri, 3-Apr-87 21:09:20 EST Article-I.D.: zyx.397 Posted: Fri Apr 3 21:09:20 1987 Date-Received: Sun, 5-Apr-87 13:03:41 EST References: <10588@topaz.RUTGERS.EDU> Reply-To: bd@zyx.UUCP (Bjorn Danielsson) Organization: ZYX Sweden AB, Stockholm Lines: 40 In article <10588@topaz.RUTGERS.EDU> chomicki@topaz.RUTGERS.EDU (Jan Chomicki) writes: >From: Francois-Michel Lang > >Any ideas about how to hack either of these? > >1. A predicate xor(G1,G2) which has the following behavior: > (...) A "real" exclusive-or should be equivalent to: G1, not(G2) ; not(G1), G2. The xor defined in the question is rather like: G1 ; \+ G1, G2. So one solution is: xor(G1,G2) :- G1 ; \+ G1, G2. This has the disadvantage that G1 is called twice. A more efficient solution is possible if (as Lee Naish pointed out) you have a retrying "if": xor(G1,G2) :- if(G1, true, G2). % if G1 then true else G2 >2. Given a predicate > > P :- A, B, C, D. > > Is it possible to rewrite P to obtain the following behavior: > (...) if a given solution of A allows B to be solved, > then don't try to resatisfy A. > But if a given solution of A does not allow B to be solved, > then do try to resatisfy A. Assuming that P has no more clauses, a possible solution might be: P :- A(X), B(X,_), !, B(X,Y), C, D. The variable X represents the solutions of A. Here too we have the disadvantage that B is called twice. We also have the requirement that the variables that represent the solutions of B for a given solution of A are easily identifiable. This may or may not be the case. -- Bjorn Danielsson, ZYX, +46 8 653205, ...mcvax!enea!zyx!bd