home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / prolog / 2446 < prev    next >
Encoding:
Text File  |  1993-01-25  |  1.9 KB  |  49 lines

  1. Newsgroups: comp.lang.prolog
  2. Path: sparky!uunet!gatech!udel!darwin.sura.net!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!nsc!voder!woodstock!news
  3. From: dyer@airplane.sharebase.com (Scot Dyer)
  4. Subject: Re: Help: making a binary predicate reversibly equal
  5. Message-ID: <1993Jan25.191246.2919@sharebase.com>
  6. Nntp-Posting-Host: airplane
  7. Reply-To: dyer@airplane.sharebase.com (Scot Dyer)
  8. Organization: NCR/ShareBase Corporation
  9. References: <C1C63u.J6n@watserv1.uwaterloo.ca>
  10. Date: Mon, 25 Jan 93 19:12:46 GMT
  11. Lines: 36
  12.  
  13. % From: jssloka@monet.uwaterloo.ca (Scott Sloka)
  14. % Subject: Help: making a binary predicate reversibly equal
  15. % Howdy.  My name is Scott Sloka and I am an AI enthusiast at the University of
  16. % Waterloo.
  17.  
  18. Howdy.
  19.  
  20. %            I have a list of facts such as: nextto(a,b) and I would like
  21. % nextto(a,b) to be equivalent to nextto(b,a).  This does not work:
  22. % nextto(X,Y):-nextto(Y,X).
  23. % because an endless loop is set up.  I am just beginning Prolog programming
  24. % because I am doing a project on abstraction and I would like to include this
  25. % parameter switch equalization in my routines for some of my predicates.  Any
  26. % pointers would be greatly appreciated.  Thanks in advance.
  27.  
  28. This is a real common problem for beginners.  You need _two_ predicates, one
  29. to handle the symmetry of the relation, and the other to provide the basic
  30. facts.  Try something like:
  31.  
  32.     nextto( X, Y ) :- nextto_fact( X, Y ).
  33.     nextto( X, Y ) :- nextto_fact( Y, X ).
  34.  
  35.     nextto_fact( a, b ).
  36.     % and whatever other 'facts' are involved.
  37.  
  38. %                 -Scott
  39.     -- Scot
  40. +------------------------+-----------------------------------------------+
  41. |Scot Dyer_Rivenburgh    | "Land of song," said the warrior bard,     |
  42. |dyer@eagle.sharebase.com| "Though all the world betrays thee,         |
  43. +------------------------+  One sword, at least, thy rights shall guard, |
  44. |(He's right, you know.) |  One faithful harp shall praise thee."     |
  45. +------------------------+-----------------------------------------------+
  46.