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.

有帮助吗?

解决方案

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.

其他提示

it means that your rule is failing immediately before binding to Passenger, and this should never happen, given the test case. The trace should report what is failing, indeed in SWI-Prolog:

fillNonDrivers(Car, Pmd, Plo, ListOfPassengers) :-
  select(Passenger, Pmd, Plo1),
  Passenger = [_,n,_],
  /* etc */
  length(Plo1, 1). % expect a failure

4 ?- fillNonDrivers([hello, 2], [[david, n, punk]], PLO, LOP).
Call: (6) fillNonDrivers([hello, 2], [[david, n, punk]], _G995, _G996)
Call: (7) lists:select(_G1100, [[david, n, punk]], _G1102)
Exit: (7) lists:select([david, n, punk], [[david, n, punk]], [])
Call: (7) [david, n, punk]=[_G1093, n, _G1099]
Exit: (7) [david, n, punk]=[david, n, punk]
Call: (7) length([], 1)
Fail: (7) length([], 1)
Redo: (7) lists:select(_G1100, [[david, n, punk]], _G1102)
Fail: (7) lists:select(_G1100, [[david, n, punk]], _G1102)
Fail: (6) fillNonDrivers([hello, 2], [[david, n, punk]], _G995, _G996)
false.

Could be a bug of your Prolog debugger ?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top