Search code examples
prologbacktrackinggnu-prologredo

Select Redoing Until Failure, Why?


I have the following function:

fillNonDrivers(Car, Pmd, Plo, ListOfPassengers) :-
  select(Passenger, Pmd, Plo1),
  Passenger = [_,n,_],
  /* etc */

I invoke it with trace on in the following way:

fillNonDrivers([hello, 2], [[david, n, punk]], PLO, LOP).
 1    1  Call: fillNonDrivers([hello,2],[[david,n,punk]],_29,_30) ? c
 2    2  Call: select(_111,[[david,n,punk]],_112) ? c
 2    2  Exit: select([david,n,punk],[[david,n,punk]],[]) ? c
 2    2  Redo: select([david,n,punk],[[david,n,punk]],[]) ? c
 2    2  Fail: select(_99,[[david,n,punk]],_100) ? c
 1    1  Fail: fillNonDrivers([hello,2],[[david,n,punk]],_29,_30) ? c
 no

I do not understand why Redo is called in the above trace. Shouldn't have the select "worked", and thus the next line invoked be

 Passenger = [_,n,_],

Could someone help explain the appearance of redo here? Thank you in advance.


Solution

  • GNU Prolog seems not to display unification goals (=) in the trace. See also this simplified example:

    GNU Prolog 1.4.2
    By Daniel Diaz
    Copyright (C) 1999-2012 Daniel Diaz
    | ?- [user].
    compiling user for byte code...
    f(X) :- X=3.
    
    user compiled, 2 lines read - 182 bytes written, 12539 ms
    
    (266 ms) yes
    | ?- trace.
    The debugger will first creep -- showing everything (trace)
    
    yes
    {trace}
    | ?- f(N).
          1    1  Call: f(_17) ? 
          1    1  Exit: f(3) ? 
    
    N = 3
    
    yes
    {trace}
    | ?- 
    

    Note that there is no step like X=3, in contrast to the SWI trace step 7 which CappeliC gave.

    So it just means that the next goal after Passenger = ... fails.