Article View: comp.lang.prolog
Article #1071Re: Simple Prolog Question
From: Peter Van Roy
Date: Mon, 13 Aug 1990 19:51
Date: Mon, 13 Aug 1990 19:51
26 lines
1487 bytes
1487 bytes
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=<B, C=B.
A choice point is generated only if A=:=B.
Sincerely,
Peter Van Roy
Technical Details
Message-ID:
<38122@ucbvax.BERKELEY.EDU>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!decwrl!ucbvax!pisces!vanroyShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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