我有以下功能:
fillNonDrivers(Car, Pmd, Plo, ListOfPassengers) :-
select(Passenger, Pmd, Plo1),
Passenger = [_,n,_],
/* etc */
我以下列方式带trace调用它:
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
我不明白为什么在上面的跟踪中调用Redo。不应该有选择"工作",因此下一行被调用
Passenger = [_,n,_],
有人能解释一下redo的出现吗?
GNU Prolog似乎没有在跟踪中显示统一目标(=
)。参见下面的简化示例:
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}
| ?-
请注意,与CappeliC给出的SWI跟踪步骤7相比,没有X=3
这样的步骤。
所以它只是意味着Passenger = ...
之后的下一个目标失败
这意味着您的规则在绑定到Passenger之前立即失败,在给定测试用例的情况下,这种情况不应该发生。跟踪应该报告出错的地方,在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.
可能是Prolog调试器的错误?