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

  1. Newsgroups: comp.lang.prolog
  2. Path: sparky!uunet!UB.com!pacbell.com!sgiblab!spool.mu.edu!howland.reston.ans.net!paladin.american.edu!news.univie.ac.at!ai-univie!bernhard
  3. From: bernhard@ai.univie.ac.at (Bernhard Pfahringer)
  4. Subject: Re: Efficiency and 'good' Prolog (was: Help !!)
  5. Message-ID: <1993Jan28.160610.25909@ai.univie.ac.at>
  6. Organization: Dept. Med.Cybernetics & Artif.Intelligence, Univ.Vienna, Austria, Europe
  7. References: <93022.184813U35395@uicvm.uic.edu>> <WUNDERWA.93Jan26114355@gsradig1.informatik.tu-muenchen.de> <9302814.20137@mulga.cs.mu.OZ.AU>
  8. Date: Thu, 28 Jan 1993 16:06:10 GMT
  9. Lines: 29
  10.  
  11. /* OK, so I could not resist.
  12.    If you really want efficient and 'clean' code, here's a version 
  13.    using one of the tricks to be found in ROK's 'CRAFT OF PROLOG':
  14.  
  15.    - no cuts
  16.    - twice as quick as max_hamer/2 (at least using Sicstus on a Sparc)
  17.  
  18. */
  19.  
  20. max_of_list( [X|L], Max) :-
  21.     max_of_list1( L, X, Max).
  22.  
  23. max_of_list1( [], Max, Max).
  24. max_of_list1( [X|L], MaxSoFar, Max) :-
  25.     compare( Rel, X, MaxSoFar),
  26.     ( Rel = =, max_of_list1( L, MaxSoFar, Max)
  27.     ; Rel = <, max_of_list1( L, MaxSoFar, Max)
  28.     ; Rel = >, max_of_list1( L, X,        Max)
  29.     ).
  30.  
  31.  
  32. /*
  33. --------------------------------------------------------------------------
  34. Bernhard Pfahringer
  35. Austrian Research Institute for  
  36. Artificial Intelligence          bernhard@ai.univie.ac.at 
  37. Schottengasse 3                  Fax:   (+43 1) 532-0652
  38. A-1010 Vienna, Austria           Phone: (+43 1) 533-6112
  39. */
  40.