[comp.lang.prolog] The "double cut"

lang@zeta.PRC.Unisys.COM (Francois-Michel Lang) (08/02/88)

In article <208500002@s.cs.uiuc.edu> gooley@s.cs.uiuc.edu writes:
>Some debuggers on some systems (C-Prolog is one, I think) show apparent
>retries of deterministic system calls.  Might this be misleading people
>into thinking that cuts are needed to prevent such retries in actual
>execution?

This could also be a "problem" for when debuggers show apparent
retries of deterministic user-defined predicates.

If your Prolog does indexing on the functor/arity
of the first argument of predicates,
the standard definition of append/3, namely

append([], L, L).
append([H|T], List, [H|Rest]) :- 
	append(T, List, Rest).

is quite deterministic.
However, if you single step through something like

| ?- trace, append([a,b,c], [1,2,3], List), fail.

depending on your debugger, you'll probably see lots of "redo"s
which you might think that a cut would have prevented.
E.g.,

| ?- trace, append([a,b,c], [1,2,3], List), fail.
[The debugger will first creep -- showing everything (trace)]
   (3) 0 Call: append([a,b,c],[1,2,3],_978) ? 
   (4) 1 Call: append([b,c],[1,2,3],_1205) ? 
   (5) 2 Call: append([c],[1,2,3],_1238) ? 
   (6) 3 Call: append([],[1,2,3],_1271) ? 
   (6) 3 Exit: append([],[1,2,3],[1,2,3]) ? 
   (5) 2 Exit: append([c],[1,2,3],[c,1,2,3]) ? 
   (4) 1 Exit: append([b,c],[1,2,3],[b,c,1,2,3]) ? 
   (3) 0 Exit: append([a,b,c],[1,2,3],[a,b,c,1,2,3]) ? 
   (3) 0 Redo: append([a,b,c],[1,2,3],[a,b,c,1,2,3]) ? 
   (4) 1 Redo: append([b,c],[1,2,3],[b,c,1,2,3]) ? 
   (5) 2 Redo: append([c],[1,2,3],[c,1,2,3]) ? 
   (6) 3 Redo: append([],[1,2,3],[1,2,3]) ? 
   (6) 3 Fail: append([],[1,2,3],_1271) ? 
   (5) 2 Fail: append([c],[1,2,3],_1238) ? 
   (4) 1 Fail: append([b,c],[1,2,3],_1205) ? 
   (3) 0 Fail: append([a,b,c],[1,2,3],_978) ? 

no
| ?- 

*** VERSUS ***

| ?- trace, append([a,b,c], [1,2,3], List), !, fail.
[The debugger will first creep -- showing everything (trace)]
   (3) 0 Call: append([a,b,c],[1,2,3],_137) ? 
   (4) 1 Call: append([b,c],[1,2,3],_377) ? 
   (5) 2 Call: append([c],[1,2,3],_410) ? 
   (6) 3 Call: append([],[1,2,3],_443) ? 
   (6) 3 Exit: append([],[1,2,3],[1,2,3]) ? 
   (5) 2 Exit: append([c],[1,2,3],[c,1,2,3]) ? 
   (4) 1 Exit: append([b,c],[1,2,3],[b,c,1,2,3]) ? 
   (3) 0 Exit: append([a,b,c],[1,2,3],[a,b,c,1,2,3]) ? 

no
| ?- 

In the second example, it looks like the cut has saved some work,
whereas it really hasn't.
----------------------------------------------------------------------------
Francois-Michel Lang
Paoli Research Center, Unisys Corporation lang@prc.unisys.com (215) 648-7256
Dept of Comp & Info Science, U of PA      lang@cis.upenn.edu  (215) 898-9511