Path: utzoo!attcan!uunet!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!sics.se!lhe From: lhe@sics.se (Lars-Henrik Eriksson) Newsgroups: comp.lang.prolog Subject: Re: Review of "The Craft of Prolog" Message-ID: <1991Feb5.135357.5213@sics.se> Date: 5 Feb 91 13:53:57 GMT References: <5771@swi.swi.psy.uva.nl> Sender: lhe@sics.se (Lars-Henrik Eriksson) Reply-To: lhe@sics.se (Lars-Henrik Eriksson) Organization: SICS, Kista (Stockholm), Sweden Lines: 28 In-Reply-To: anjo@swi.psy.uva.nl (Anjo Anjewierden) In article <5771@swi.swi.psy.uva.nl>, anjo@swi (Anjo Anjewierden) writes: > >/* 1 */ max(X, Y, X) :- X >= Y. > max(X, Y, Y) :- X < Y. > >/* 2 */ max(X, Y, X) :- X >= Y, !. > max(X, Y, Y) :- X < Y. > >/* 3 */ max(X, Y, X) :- X >= Y, !. > max(X, Y, Y). > >/* 4 */ max(X, Y, Z) :- X >= Y, !, Z = X. > max(X, Y, Y). > >If your preference is with the first program (called the pure version >because it is a straightforward implementation of the problem >specification) there is no need to read the book. I would be very >surprised if anyone selected number two. Actually, I often use version number two. Why? I really prefer the pure version, but inserting as cut rids me of a useless choice point. At the same time the cut is semantically redundant (I believe O'Keefe calls this a "green" cut). -- Lars-Henrik Eriksson Internet: lhe@sics.se Swedish Institute of Computer Science Phone (intn'l): +46 8 752 15 09 Box 1263 Telefon (nat'l): 08 - 752 15 09 S-164 28 KISTA, SWEDEN