[mercury-users] How did Mercury do away with the cut?

Ralph Becket rbeck at microsoft.com
Fri Jul 6 00:54:20 AEST 2001


> From: Terrence Monroe Brannon [mailto:tmbranno at oracle.com]
> Sent: 05 July 2001 15:27
> 
> I always found the cut to be a confusing part of Prolog. I was
> wondering how Mercury managed to eliminate the necessity for this
> predicate.

"Green" cuts in pure Prolog (i.e. those that do not affect the
declarative semantics of a program, but which are present for
efficiency's sake) are subsumed by Mercury's mode declarations.

"Red" cuts in Prolog do change the declarative semantics of
the program and are subsumed by Mercury's commited choice
determinism declarations.  Placement of red cuts in Prolog usually
requires an understanding of Prolog's execution strategy.  To obtain
almost exactly the same effect in Mercury you'd have to compile your 
program with --no-reorder-conj (you still can't guarantee exactly
the same behaviour because the compiler is still allowed to reorder
to satisfy mode constraints - that is, where Prolog would fail, your
Mercury program may succeed.)

> In eliminating it, is it still possible to make programs semantically
> equivalent to Prolog in about the same amount of code?

To a first order approximation, yes.  You just have to remove the cuts
and add the appropriate mode declarations.  However, there are several
aspects of Prolog that you can't carry over to Mercury, such as some 
difference list idioms and assert and retract - and IO is completely
different, of course.  Oh yes, Prolog's if-then-else includes an
implicit cut where Mercury's does not.  For example

	( member(X, [1, 2, 3]) -> odd(X) ; fail ), X = 3

will fail under Prolog but succeed under Mercury.

- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list