4

这是我想要得到的序言输出:

?-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).
4

1 回答 1

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),
...

可能没用...

于 2013-05-03T15:44:37.243 回答