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

From: Kish Shen <kisshen_at_...5...>
Date: Tue, 25 Jan 2011 21:22:46 +0000
On 25/01/2011 10:20, Ulrich Scholz wrote:
> 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.

This type-testing (indexing) is done on a specific argument in a clause, 
as I explained previously. This is also described in section 6.7 of the 
user manual. In your example, you need to consider the types of both 
arguments in order to uniquely select a single clause, and this is *not* 
done in ECLiPSe.

Here is what ECLiPSe does for your example:

 > >t2(T1, _T2) :-
 > >     free(T1),
 > >     !,
 > >     writeln(a).
 > >
 > >t2(_T1, T2) :-
 > >     T2 \== [],
 > >     writeln(b).
 > >
 > >t2(_T1, []) :-
 > >     writeln(c).

if arg1 (T1) is free, commit to the first clause, otherwise create a 
choicepoint, and try the second and third clauses in turn.

You need another test on the second argument (T2) at this point to
select between these two clauses. This is not done by ECLiPSe.

So if you index on the first argument, you can either exclude or commit 
to the first clause. If you index on the second argument instead, then
no selection can be done in your example, and all 3 clauses have to be 
tried, this is because the first clause does not impose any restriction 
on the second argument (T2). The ECLiPSe compiler is smart enough to 
figure this out, and so decide to index on the first argument.

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

No, the choicepoint is created because looking at the first argument 
alone, you cannot select between the second and third clause.

If you miss out the first clause in your example, then indexing can be 
done between your remaining clauses, even with your original code, if 
you call t2 with the second argument instantiated. [The difference 
happens when the call has a variable for the second argument]



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 Tue Jan 25 2011 - 21:23:21 CET

This archive was generated by hypermail 2.3.0 : Tue May 14 2019 - 03:13:24 CEST