I use swi prolog and my code like this. I read data predicate from file and its arity count can change. How can I generalize it. For example, If data(a1,b1,c1) writes in the file, how can I find solution? Do you have any idea?
> basla:-consult('test.pl'),
> answer(L1,L2,L3,L4,L5),
> list_to_set(L1, X),
>
> write(X).
> answer(L1,L2,L3,L4,L5):-
> findall(First, data(First,_,_,_,_),L1),
> findall(Second, data(_,Second,_,_,_),L2),
> findall(Third, data(_,_,Third,_,_),L3).
If the arity of a predicate seems to change, it's almost always better to make it arity one and give it a list argument. Your
findall
queries can then be extended with a call tonth1
ornth0
.