Prolog output: list item, not position

This prologue outputs what I'm trying to get:

?-mill(try(a,b,c,d,e),R). R = (e:-c) ; 

With the code below, I get numerical output. How can I get the output (e:-c) and not their position numbers in the list?

 ?-mill(try(a,b,c,d,e),R). R = (5:-3) ; 

code:

 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
source share
1 answer

With this modification

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

I get

 ?- gtrace,mill(try(a,b,c,d,e),R). R = (e:-c) ; false. 

You have to check singleton PP , target

 ..., calc(Table,A,+,B,+,PP), ... 

may be useless ...

0
source

Source: https://habr.com/ru/post/1479016/


All Articles