home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.prolog
- 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
- From: wunderwa@informatik.tu-muenchen.de (Jens Wunderwa)
- Subject: Re: Efficiency and 'good' Prolog (was: Help !!)
- In-Reply-To: C. M. Sperberg-McQueen's message of Fri, 22 Jan 1993 18:48:13 CST
- References: <lenn.726916615@du9ds4> <j_hamer-210193105028@john-ha.cs.aukuni.ac.nz>
- <93021.154835U35395@uicvm.uic.edu>
- <1993Jan21.223806.19004@colorado.edu>
- <93022.184813U35395@uicvm.uic.edu>
- Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem)
- Organization: Inst. fuer Informatik, TU Muenchen, Germany
- Date: Tue, 26 Jan 1993 16:43:55 GMT
- Message-ID: <WUNDERWA.93Jan26114355@gsradig1.informatik.tu-muenchen.de>
- Lines: 31
-
- I have edited both max-versions for better comparability:
-
- max_heiner( [Max], Max ) :- !.
- max_heiner( [MaxSoFar, First |Rest], Max ) :-
- MaxSoFar > First, !,
- max_heiner( [MaxSoFar |Rest], Max ).
- max_heiner( [_|Rest], Max ) :-
- max_heiner( Rest, Max ).
-
-
- max_hamer( [First |Rest], Max ) :-
- max_hamer( First, Rest, Max ).
-
- max_hamer( Max, [], Max ) :- !.
- max_hamer( MaxSoFar, [First |Rest], Max ) :-
- MaxSoFar > First, !,
- max_hamer( MaxSoFar, Rest, Max ).
- max_hamer( _, [First |Rest], Max ) :-
- max_hamer( First, Rest, Max ).
-
-
- The difference seems to be almost of a syntactic character. Hamer
- uses a temporary variable for the greatest element seen so far
- whereas Heiner uses the first element of the input list for that
- purpose.
-
- I think it's bad style to misuse the input for constructing
- the result instead of applying the standard accumulator pair technique.
-
- Heiner's solution needs heap space for storing the intermediate
- result making it 30 % slower.
-