home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / prolog / 1524 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  1.5 KB

  1. Path: sparky!uunet!mcsun!sunic!dkuug!diku!torbenm
  2. From: torbenm@diku.dk (Torben AEgidius Mogensen)
  3. Newsgroups: comp.lang.prolog
  4. Subject: Re: transitive and symetric relations
  5. Message-ID: <1992Aug13.111745.17980@odin.diku.dk>
  6. Date: 13 Aug 92 11:17:45 GMT
  7. References: <SWK.92Aug10220513@seymour.mlb.semi.harris.com> <189@syllogi.syllogic.nl>
  8. Sender: torbenm@freke.diku.dk
  9. Distribution: comp.lang.prolog
  10. Organization: Department of Computer Science, U of Copenhagen
  11. Lines: 29
  12.  
  13. fdb@syllogic.nl (Frank de Bruijn) writes:
  14.  
  15. >swk@seymour.mlb.semi.harris.com (Song W. Koh) writes:
  16.  
  17. >>[I'm a] prolog beginner.  I am having trouble describing transitive and
  18. >>symetric relations without stack overflows.  Things like:
  19.  
  20. >>distance(X,Y,D) :- distance(Y,X,D).
  21.  
  22. >I see, are you blind, or just too lazy to read a decent textbook on
  23. >PROLOG? Even the "not so good books" describe this.
  24.  
  25. >The standard solution is to use a different predicate name for the distance
  26. >facts. (It has always struck me as a bit of a diappointment though)
  27.  
  28. >distance(X, Y, D):- distance_fact(X, Y, D).
  29. >distance(X, Y, D):- distance_fact(Y, X, D).
  30. >distance(X,Z,D):- distance_fact(X,Y,D1), distance_fact(Y,Z,D2), D is D1 + D2 .
  31.  
  32. This will not work: it will not find distances of points that require
  33. paths more than two long. A correct formulation of the transitive
  34. clause is
  35.  
  36. distance(X,Z,D):- distance_fact(X,Y,D1), distance(Y,Z,D2), D is D1 + D2.
  37.  
  38. So be sure to get your answers right before you flame someone for
  39. asking the obvious.
  40.  
  41.     Torben Mogensen (torbenm@diku.dk)
  42.