Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!satisfied.elf.com!wizard.pn.com!Germany.EU.net!Munich.Germany.EU.net!ecrc!news
From: micha@ecrc.de (Micha Meier)
Subject: Re: Question about "cut"
Message-ID: <D2Joy1.3Fs@ecrc.de>
Sender: news@ecrc.de
Reply-To: micha@ecrc.de
Organization: European Computer-Industry Research Centre
References: <3f43s6$go0@hustle.rahul.net>
Date: Tue, 17 Jan 1995 10:25:12 GMT
Lines: 44

In article go0@hustle.rahul.net, Bill Hogan <bhogan@rahul.net> writes:
>   As I understand it, two things happen when a cut ("!") is reached in a 
> rule:
> 
>   1. The Prolog processor is prevented from finding any answers in 
> addition to any it has found at the point the cut is reached, and
> 
>   2. The Prolog processor is prevented from consulting any remaining 
> clauses in the current set of clauses.
> 
>   If this is so, might it not be useful sometimes to be able to separate
> these two effects? 
> 
>   Suppose I let !+ denote the former effect and !- the latter.
> 
>   Can anyone suggest a situation in which I would want to use !+ but 
> not !- and a situation in which I would want to use !- but not !+, i.e.,
> 
>   1. !+ but not !-
> 
>      p(X,...) :- do_q_at_most_once(X), !+ , ...
>      p(X,...) :- but_try_this_in_any_case(X), ...
> 
> where `do_q_at_most_once' is inherently "nondeterministic", and

In this case one would rather use the predicate once/1 to stress the fact
that the commit concerns only one or several goals in the current clause.

> 
>   2. !- but not !+
> 
>      p(X,...) :- do_w_possibly_many_times(X), !-, ...
>      p(X,...) :- but_do_not_try_this_if_w_ever_succeeds(X), ...
> 
This is the so-called "soft cut" that has been implemented in a number of Prolog
systems.

>   Could this distinction be implemented in a way that would fit in nicely 
> with however it is that "cut" is normally implemented? 

Yes, e.g. SICStus has the if/3 predicate, Eclipse has the A *-> B; C construct.

--Micha

