这是我想要得到的prolog输出:
?-mill(try(a,b,c,d,e),R).
R = (e:-c) ;
使用下面的代码我得到数字输出。如何获得(e:-c)
输出,而不是列表位置编号?
?-mill(try(a,b,c,d,e),R).
R = (5:-3) ;
代码:
try(-,+,+,+,+).
try(-,-,+,+,+).
try(+,+,+,+,+).
try(+,+,-,-,-).
try(+,-,-,+,-).
construct(X, Y):-
functor(X,F,N), functor(Y,F,N).
row_number(X, Y):-
findall(a, X, List), length(List, Y).
reason(Table,A,B):-
calc(Table,A,+,PA),
calc(Table,B,+,PB),
calc(Table,A,+,B,+,PP),
calc(Table,A,+,B,-,PM),
PA=PB,
PM=0.
calc(Table,Column,Body,Number):-
construct(Table,Var),
arg(Column,Var,Body),
row_number(Var,Number).
calc(Table,A,Abody,B,Bbody,Number):-
construct(Table,Var),
arg(A,Var,Abody),
arg(B,Var,Bbody),
row_number(Var,Number).
mill(Table,B:-A):-
functor(Table,_,B),
row_number(reason(Table,A,B),1),
reason(Table,A,B).
答案 0 :(得分:0)
通过此修改
mill(Table,B_:-A_):-
functor(Table,_,B),
row_number(reason(Table,A,B),1),
reason(Table,A,B),
arg(A, Table, A_),
arg(B, Table, B_).
我得到了
?- gtrace,mill(try(a,b,c,d,e),R).
R = (e:-c) ;
false.
您应该检查单一PP
,即该目标
...,
calc(Table,A,+,B,+,PP),
...
可能没用......