Path: utzoo!attcan!uunet!decwrl!ucbvax!pisces!vanroy From: vanroy@pisces (Peter Van Roy) Newsgroups: comp.lang.prolog Subject: Re: Simple Prolog Question Message-ID: <38122@ucbvax.BERKELEY.EDU> Date: 13 Aug 90 19:51:58 GMT Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: vanroy@pisces (Peter Van Roy) Organization: University of California at Berkeley Lines: 26 In article <3553@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: > >I'd prefer that too. Indeed, Debray's SB-Prolog will let you write that >last clause as > remove_leading_blanks([H|T], L) :- > ( H =:= " ", > remove_leading_blanks(T, L) > ; H =\= " ", > L = [H|T] > ). >and the compiler is smart enough to notice that the two tests conflict, >and it will plant the cut for you. That's the _really_ nice way to write it. >(Does the new Berkeley compiler do this too?) Yes, the Berkeley compiler generates deterministic code for this example, but it does not "plant a cut". A single conditional branch is generated to distinguish between the two arms of the disjunction. Even if the two tests do not conflict entirely, the compiler is smart enough to generate a choice point only when they overlap. For example, consider: max(A, B, C) :- A>=B, C=A. max(A, B, C) :- A=