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

  1. Newsgroups: comp.lang.prolog
  2. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!math.fu-berlin.de!informatik.tu-muenchen.de!lan!wunderwa
  3. From: wunderwa@informatik.tu-muenchen.de (Jens Wunderwa)
  4. Subject: Re: Efficiency and 'good' Prolog (was: Help !!)
  5. In-Reply-To: C. M. Sperberg-McQueen's message of Fri, 22 Jan 1993 18:48:13 CST
  6. References: <lenn.726916615@du9ds4> <j_hamer-210193105028@john-ha.cs.aukuni.ac.nz>
  7.     <93021.154835U35395@uicvm.uic.edu>
  8.     <1993Jan21.223806.19004@colorado.edu>
  9.     <93022.184813U35395@uicvm.uic.edu>
  10. Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem)
  11. Organization: Inst. fuer Informatik, TU Muenchen, Germany
  12. Date: Tue, 26 Jan 1993 16:43:55 GMT
  13. Message-ID: <WUNDERWA.93Jan26114355@gsradig1.informatik.tu-muenchen.de>
  14. Lines: 31
  15.  
  16. I have edited both max-versions for better comparability:
  17.  
  18. max_heiner( [Max], Max ) :- !.
  19. max_heiner( [MaxSoFar, First |Rest], Max ) :-
  20.     MaxSoFar > First, !, 
  21.     max_heiner( [MaxSoFar |Rest], Max ).
  22. max_heiner( [_|Rest], Max ) :-
  23.     max_heiner( Rest, Max ).
  24.  
  25.  
  26. max_hamer( [First |Rest], Max ) :-
  27.     max_hamer( First, Rest, Max ).
  28.  
  29. max_hamer( Max, [], Max ) :- !.
  30. max_hamer( MaxSoFar, [First |Rest], Max ) :-
  31.     MaxSoFar > First, !, 
  32.     max_hamer( MaxSoFar, Rest, Max ).
  33. max_hamer( _, [First |Rest], Max ) :-
  34.     max_hamer( First, Rest, Max ).
  35.  
  36.  
  37. The difference seems to be almost of a syntactic character. Hamer 
  38. uses a temporary variable for the greatest element seen so far 
  39. whereas Heiner uses the first element of the input list for that 
  40. purpose. 
  41.  
  42. I think it's bad style to misuse the input for constructing
  43. the result instead of applying the standard accumulator pair technique.
  44.  
  45. Heiner's solution needs heap space for storing the intermediate 
  46. result making it 30 % slower.
  47.