🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2621

Re: Prolog control structures

#2621
From: micha
Date: Thu, 02 Apr 1987 18:27
29 lines
1383 bytes
Both of the required predicates can be defined using one predicate
	succeeds(X)
that succeeds if X does, without binding variables and leaving choice
points (if X has some side effects, I doubt you can define it without
assert). The xor(A, B) can be defined as

	xor(A, _) :- succeeds(A), !, A.
	xor(_, B) :- B.

and the other one

	P :- A, succeeds(B), !, B, C, D.

Not to forget the definition of succeeds/1:

	succeeds(X) :- not(not(X)).

or alternatively

	succeeds(X) :- replace_vars(X, Y), Y, !.

where replace_vars(X, Y) makes a copy of X with fresh variables.

This has, of course the disadvantage that the predicate is called twice,
first in succeeds(X) and then the proper call, the problem is
similar to writing setof/3 in pure Prolog - you can make it but
it is not very efficient.

--Micha
Technical Details
Message-ID: <275@ecrcvax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!mcvax!unido!ecrcvax!micha
References: <topaz.10588>

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!seismo!mcvax!unido!ecrcvax!micha
From: micha@ecrcvax.UUCP
Newsgroups: comp.lang.prolog
Subject: Re: Prolog control structures
Message-ID: <275@ecrcvax.UUCP>
Date: Thu, 2-Apr-87 13:27:08 EST
Article-I.D.: ecrcvax.275
Posted: Thu Apr  2 13:27:08 1987
Date-Received: Sat, 4-Apr-87 16:14:39 EST
References: <topaz.10588>
Reply-To: mcvax!unido!ecrcvax!micha (Micha Meier)
Organization: ECRC, D-8000 Muenchen 81, W. Germany
Lines: 29