🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2431

Re: Efficiency and 'good' Prolog (was: Help !!)

#2431
From: Bernhard Pfahringer
Date: Thu, 28 Jan 1993 16:06
29 lines
1501 bytes
/* OK, so I could not resist.
   If you really want efficient and 'clean' code, here's a version 
   using one of the tricks to be found in ROK's 'CRAFT OF PROLOG':

   - no cuts
   - twice as quick as max_hamer/2 (at least using Sicstus on a Sparc)

*/

max_of_list( [X|L], Max) :-
	max_of_list1( L, X, Max).

max_of_list1( [], Max, Max).
max_of_list1( [X|L], MaxSoFar, Max) :-
	compare( Rel, X, MaxSoFar),
	( Rel = =, max_of_list1( L, MaxSoFar, Max)
	; Rel = <, max_of_list1( L, MaxSoFar, Max)
	; Rel = >, max_of_list1( L, X,        Max)
	).


/*
--------------------------------------------------------------------------
Bernhard Pfahringer
Austrian Research Institute for  
Artificial Intelligence          bernhard@ai.univie.ac.at 
Schottengasse 3                  Fax:   (+43 1) 532-0652
A-1010 Vienna, Austria           Phone: (+43 1) 533-6112
*/
Technical Details
Message-ID: <1993Jan28.160610.25909@ai.univie.ac.at>
Path: arc1-ca.pugleaf.net!sparky!uunet!UB.com!pacbell.com!sgiblab!spool.mu.edu!howland.reston.ans.net!paladin.american.edu!news.univie.ac.at!ai-univie!bernhard
References: <93022.184813U35395@uicvm.uic.edu>> <WUNDERWA.93Jan26114355@gsradig1.informatik.tu-muenchen.de> <9302814.20137@mulga.cs.mu.OZ.AU>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.prolog
Path: arc1-ca.pugleaf.net!sparky!uunet!UB.com!pacbell.com!sgiblab!spool.mu.edu!howland.reston.ans.net!paladin.american.edu!news.univie.ac.at!ai-univie!bernhard
From: bernhard@ai.univie.ac.at (Bernhard Pfahringer)
Subject: Re: Efficiency and 'good' Prolog (was: Help !!)
Message-ID: <1993Jan28.160610.25909@ai.univie.ac.at>
Organization: Dept. Med.Cybernetics & Artif.Intelligence, Univ.Vienna, Austria, Europe
References: <93022.184813U35395@uicvm.uic.edu>> <WUNDERWA.93Jan26114355@gsradig1.informatik.tu-muenchen.de> <9302814.20137@mulga.cs.mu.OZ.AU>
Date: Thu, 28 Jan 1993 16:06:10 GMT
Lines: 29