home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / prolog / 1602 < prev    next >
Encoding:
Text File  |  1992-08-26  |  1.6 KB  |  45 lines

  1. Newsgroups: comp.lang.prolog
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!Sirius.dfn.de!chx400!bernina!neptune!nugget.inf.ethz.ch!marti
  3. From: marti@nugget.inf.ethz.ch (Robert Marti)
  4. Subject: Re: Help on problem needed!
  5. Message-ID: <1992Aug26.130909.17909@neptune.inf.ethz.ch>
  6. Keywords: help
  7. Sender: news@neptune.inf.ethz.ch (Mr News)
  8. Nntp-Posting-Host: nugget.inf.ethz.ch
  9. Organization: Dept. Informatik, Swiss Federal Institute of Technology (ETH), Zurich, CH
  10. References: <meskes.713709771@ulysses> <1992Aug25.074623.25450@greco-prog.fr>
  11. Date: Wed, 26 Aug 1992 13:09:09 GMT
  12. Lines: 31
  13.  
  14. In article <1992Aug25.074623.25450@greco-prog.fr>, billaud@greco-prog.fr
  15. (Michel BILLAUD) writes:
  16. |> In article <meskes.713709771@ulysses>
  17. |> meskes@ulysses.informatik.rwth-aachen.de (Michael Meskes) writes:
  18. |> 
  19. |> > Can you program a IF...THEN...ELSE in Prolog without using the cut?
  20. |> 
  21. |> No. a proof by contradiction:
  22.  
  23. [ proof deleted ]
  24.  
  25. I am sorry to contradict your contradiction ;-)  As someone else has
  26. pointed out, it _is_ possible to program if-then-else without cut
  27. IN CERTAIN SPECIAL CASES.
  28.  
  29. Canonical example:
  30.   IF X >= Y THEN Max := X ELSE Max := Y END
  31.  
  32. Prolog translation:
  33.   % max(+X,+Y,?Max): Max is the maximum of X and Y
  34.   max(X,Y,X) :- X >= Y.
  35.   max(X,Y,Y) :- X < Y.
  36.  
  37. This works because < happens to be the logical negation of >=
  38. provided that both arguments are ground.
  39.  
  40. -- 
  41. Robert Marti                    |  Phone:    +41 1 254 72 60
  42. Informationssysteme             |  FAX:      +41 1 262 39 73
  43. ETH-Zentrum                     |  E-Mail:   marti@inf.ethz.ch
  44. CH-8092 Zurich, Switzerland     |
  45.