🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2620

Re: Prolog control structures

#2620
From: lee
Date: Thu, 02 Apr 1987 07:57
51 lines
2491 bytes
In article <10588@topaz.RUTGERS.EDU> chomicki@topaz.RUTGERS.EDU
(Jan Chomicki) writes:
>From: Francois-Michel Lang <lang%omega.PRC.Unisys.COM@cis.upenn.edu>
>Any ideas about how to hack either of these?
>
>1. A predicate xor(G1,G2)
You need "soft cut" for this:

xor(G1, _) :-
	call(G1),
	$soft_cut.	% (this is what its called in MU-Prolog)
xor(_, G2) :-
	call(G2).

When soft cut is called, it removes the choice point of the parent call
(xor in this case) but no others.  It is pretty easy to implement this
when you are writing a Prolog system, but difficult afterwards.  It is
not a standard construct and has no standard name.  I'm not sure how
many Prolog systems have it.  It is useful for a version of "if" which
can return multiple answers to the condition (see L. Naish, "Negation
and Quantifiers in NU-Prolog", 3rd ICLP, 1986).  For this reason,
NU-Prolog and recent versions of MU-Prolog have soft cut implemented
internally.  I guess LM-Prolog does also, since it has a retrying
version of "if".

>2. Given a predicate
>
>      P :- A, B, C, D.
>
>   Is it possible to rewrite P to obtain the following behavior:
>   If the goal A initially succeeds, then
>      if B doesn't succeed, backtrack into A.  (This is quite normal.)
>   However, if A initially succeeds, and B does too,
>      then prevent backtracking into A.

P :- A, B, !, C, D.  % if there are no more clauses, or

P :- once (A, B), C, D.	% if you Prolog system has once/1

Does what you said.  It also prevents multiple solutions to B, which
you may want (this was not said in the original posting).  If you
dont want to remove choice point from the execution of B, I cant think
of how to do it in Prolog systems I know of (ancestor cut is not
flexible enough). 

	Lee Naish

CSNET:	lee@mulga.oz
ARPA:	munnari!lee@seismo
UUCP:	{seismo,mcvax,ukc,prlb2,ubc-vision}!munnari!lee
	{decvax,vax135,eagle,pesnta}!mulga!lee
Technical Details
Message-ID: <1883@mulga.OZ>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!brl-adm!seismo!munnari!mulga!lee
References: <10588@topaz.RUTGERS.EDU>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!brl-adm!seismo!munnari!mulga!lee
From: lee@mulga.UUCP
Newsgroups: comp.lang.prolog
Subject: Re: Prolog control structures
Message-ID: <1883@mulga.OZ>
Date: Thu, 2-Apr-87 02:57:54 EST
Article-I.D.: mulga.1883
Posted: Thu Apr  2 02:57:54 1987
Date-Received: Sat, 4-Apr-87 13:08:37 EST
References: <10588@topaz.RUTGERS.EDU>
Reply-To: lee@mulga.OZ (Lee Naish)
Organization: Computer Science, University of Melbourne
Lines: 51