home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / prolog / 2453 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  1.3 KB

  1. Path: sparky!uunet!spool.mu.edu!agate!doc.ic.ac.uk!uknet!edcastle!aiai!ken
  2. From: ken@aiai.ed.ac.uk (Ken Johnson)
  3. Newsgroups: comp.lang.prolog
  4. Subject: Re: Help: making a binary predicate reversibly equal
  5. Message-ID: <8252@skye.ed.ac.uk>
  6. Date: 26 Jan 93 11:08:38 GMT
  7. References: <C1C63u.J6n@watserv1.uwaterloo.ca>
  8. Sender: news@aiai.ed.ac.uk
  9. Followup-To: comp.lang.prolog
  10. Organization: William's Wonderful Wonky Widget Warehouse
  11. Lines: 45
  12.  
  13.  
  14. In article <C1C63u.J6n@watserv1.uwaterloo.ca> jssloka@monet.uwaterloo.ca
  15. (Scott Sloka) writes:
  16.  
  17. #  I have a list of facts such as: nextto(a,b) and I would like nextto(a,b)
  18. #  to be equivalent to nextto(b,a). 
  19.  
  20.  
  21. This is a common problem. The usual solution is
  22.  
  23. next_to(A,B) :-
  24.     next_to_fact(A,B).
  25.  
  26. next_to(A,B) :-
  27.     next_to_fact(B,A).
  28.  
  29.  
  30. next_to_fact(e,r).
  31. next_to_fact(i,o).
  32. next_to_fact(o,p).
  33. next_to_fact(q,w).
  34. next_to_fact(r,t).
  35. next_to_fact(t,y).
  36. next_to_fact(u,i).
  37. next_to_fact(w,e).
  38. next_to_fact(y,u)
  39.  
  40.  
  41. Example run
  42.  
  43. | ?- next_to(q,w).
  44.  
  45. yes
  46. | ?- next_to(w,q).
  47.  
  48. yes
  49. | ?- next_to(a,b).
  50. no
  51.  
  52.  
  53. -- 
  54. Son, all the pretty, intelligent, healthy     #    I have discovered of this
  55. young women are taken. It's a basic rule of   #    basic rule of the universe
  56. the universe, and if you don't like it, go    #    a most remarkable proof,
  57. somewhere else.        -- my dad  1906-1992   #    which this .signature is too
  58.