🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2417

Re: Help: making a binary predicate reversibly equal

#2417
From: Scot Dyer
Date: Mon, 25 Jan 1993 19:12
36 lines
2040 bytes
% From: jssloka@monet.uwaterloo.ca (Scott Sloka)
% Subject: Help: making a binary predicate reversibly equal
% 
% Howdy.  My name is Scott Sloka and I am an AI enthusiast at the University of
% Waterloo.

Howdy.

%            I have a list of facts such as: nextto(a,b) and I would like
% nextto(a,b) to be equivalent to nextto(b,a).  This does not work:
% 
% nextto(X,Y):-nextto(Y,X).
% 
% because an endless loop is set up.  I am just beginning Prolog programming
% because I am doing a project on abstraction and I would like to include this
% parameter switch equalization in my routines for some of my predicates.  Any
% pointers would be greatly appreciated.  Thanks in advance.

This is a real common problem for beginners.  You need _two_ predicates, one
to handle the symmetry of the relation, and the other to provide the basic
facts.  Try something like:

	nextto( X, Y ) :- nextto_fact( X, Y ).
	nextto( X, Y ) :- nextto_fact( Y, X ).

	nextto_fact( a, b ).
	% and whatever other 'facts' are involved.

%                 -Scott
	-- Scot
+------------------------+-----------------------------------------------+
|Scot Dyer_Rivenburgh    | "Land of song," said the warrior bard,	 |
|dyer@eagle.sharebase.com| "Though all the world betrays thee,		 |
+------------------------+  One sword, at least, thy rights shall guard, |
|(He's right, you know.) |  One faithful harp shall praise thee."	 |
+------------------------+-----------------------------------------------+
Technical Details
Message-ID: <1993Jan25.191246.2919@sharebase.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!udel!darwin.sura.net!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!nsc!voder!woodstock!news
References: <C1C63u.J6n@watserv1.uwaterloo.ca>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.prolog
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!udel!darwin.sura.net!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!nsc!voder!woodstock!news
From: dyer@airplane.sharebase.com (Scot Dyer)
Subject: Re: Help: making a binary predicate reversibly equal
Message-ID: <1993Jan25.191246.2919@sharebase.com>
Nntp-Posting-Host: airplane
Reply-To: dyer@airplane.sharebase.com (Scot Dyer)
Organization: NCR/ShareBase Corporation
References: <C1C63u.J6n@watserv1.uwaterloo.ca>
Date: Mon, 25 Jan 93 19:12:46 GMT
Lines: 36