Re: Problem regarding soft cut(*->).

From: Warwick Harvey <wh_at_icparc.ic.ac.uk>
Date: Mon 06 Jan 2003 02:22:04 PM GMT
Message-ID: <20030106142204.T16824@tempest.icparc.ic.ac.uk>
On Thu, Jan 02, 2003 at 09:59:44PM +0100, Jinyi wrote:
> >
> > This is a bit of an anomaly in Eclipse: it will only work when
> > the *-> occurs in compiled code. I.e. if you compile a clause like
> >
> > p(X,Y) :- ( member(X,[1,3]) *-> Y #= X+1; Y #=0 ).
> >
> > you will be able to call p(X,Y).
> >
> 
>   I still got problem:
> 
>   have the toy program follows compiled
>  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> :-lib(fd).
> :-op(1050, xfx, *->).
> :-import (*->)/2 from sepia_kernel.
> 
> p(X,Y) :- member(X,[1,3]) *-> Y = odd ;  member(X,[2,4]) *-> Y = even.
> 
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> 
>  It works when quering ?- p(X,Y).
> 
>  But query ?- p(2,Y).
> System prompts following error message:
> calling an undefined procedure sepia_kernel : (member(2, [2, 4]) *-> Y=even)
> in module eclipse
> Abort
> 
> Does that mean we cannot have nested soft cuts?

No, it means you're missing the "else" clause from your innermost "soft cut"
(unlike a normal if-then-else, apparently the soft cut does not have a
default else clause --- besides, if the default else was "fail" like with a
normal if-then-else, then "*->" with no else would be equivalent to "," and
you might as well use that).

Note also that I'd recommend always adding parentheses when using any
if-then-else style construct to make the scope explicit, and always adding
explicit else clauses.

Here's a couple of example versions of p/2 which work OK:

    % This is equivalent to what I think you were trying to do.
p(X, Y) :-
	( member(X, [1, 3]) *->
		Y = odd
	;
		member(X, [2, 4]),
		Y = even
	).

    % This shows nested soft cuts working.
p(X, Y) :-
	( member(X, [1, 3]) *->
		Y = odd
	; member(X, [2, 4]) *->
		Y = even
	;
		Y = unknown
	).

Cheers,
Warwick
Received on Mon Jan 06 14:23:58 2003

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:20 PM GMT GMT