Re: [eclipse-clp-users] compiler leaves spurious choice points

From: Ulrich Scholz <wanderer_at_...190...>
Date: Tue, 25 Jan 2011 11:20:32 +0100
Dear Kish,

thanks for your answer.  Of course, I did not expect ECLiPSe to deduce the
question in the general case.  But section 6.7 of the user manual seems to
imply that ECLiPSe does it for the type-testing information given at the
beginning of clauses.

So I guess, the choice point was left because my code was not cut safe.
Thanks for spotting the bug!

Best regards,

Ulrich Scholz


On Thu, Jan 20, 2011 at 07:54:27PM +0000, Kish Shen wrote:
> On 19/01/2011 15:10, Ulrich Scholz wrote:
> >t2(T1, _T2) :-
> >     free(T1),
> >     !,
> >     writeln(a).
> >
> >t2(_T1, T2) :-
> >     T2 \== [],
> >     writeln(b).
> >
> >t2(_T1, []) :-
> >     writeln(c).
> 
> Hi Ulrich,
> 
> The general question you seem to be asking is:
> 
> "Is it possible to ensure that, if only one clause of a predicate
> will lead to success for a given call, we will always commit to that
> clause without creating a choice-point?"
> 
> The short answer is: no, because it is impossible for the system to
> anticipate all possibilities of failures in the other clauses.


> > Is there any way to prevent this?  It is somewhat distracting
> during > tracing and bug fixing.
> 
> The standard way to avoid such choice-points is to add additional
> cuts. For your code:
> 
> t2(_T1, T2) :-
>     T2 \== [], !,
>     writeln(b).
> t2(_T1, T2) :-
>     T2 == [],
>     writeln(c).
> 
> 
> [I have changed your code to make the cut "safe", I am assuming this is
> the intention of your original code, i.e. that clauses 2 and 3 are
> truly mutually exclusive (previously, the clauses were not mutually
> exclusive if T2 is called as a variable)]
Received on Tue Jan 25 2011 - 10:20:43 CET

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