Re: [eclipse-clp-users] Backtracking over current predicate only

From: Kish Shen <kisshen_at_...5...>
Date: Fri, 14 May 2010 16:57:29 +0100
Christian Wirth wrote:
> Hi,
> 
> how can i define a cut that allows backtracking over the current 
> predicate but not over another predicate ?
> example:
> 
> pred(aPred(X)) :- call(X).
> pred(X) :- anotherCall(X).
> 
> i now want to define a cut that creates all solutions for call(X), if 
> the first perdicate gets matched, but it should prevent matching the 
> other one.
> I'm currently using pred(X) :- 
> functor(X,F,A),not(F==aPred),anotherCall(X), but i want to replace this 
> because speedup is very essential.
> 
> .. hope this is possible.
> 

Hi Christian,

If by 'creates all solutions for call(X)' you mean 'allows the 
backtracking over call(X)' as you implied in your first paragraph, then 
what you want is referred to as the `soft cut' in Prolog literature, and 
in ECLiPSe, this is provided by the *->/2 construct (see the reference 
manual entry for *->/2 (you can use help (*->)/2 at the ECLiPSe 
top-level to access this information).

Using soft cut, your example can be written as:

pred(X0) :-
    X0 = aPred(X), 	
    ( call(X) *-> true ; anotherCall(X0))

(I have duplicated your aPred(X) wrapper behaviour -- did you truly 
intend this behaviour?)

anotherCall(X0) is only executed if call(X) has no solution at all; 
otherwise all solutions of call(X) can be obtained via backtracking.

A warning: support for soft cuts is quite controversial within the 
Prolog community, and my suggestion is that you should avoid using it if 
possible.

Cheers,

Kish


-- 
This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.
Received on Fri May 14 2010 - 15:57:38 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:20 CEST