Is it possible to have a “variable arity predicate” in Prolog?
I mean something like this:
my_predicate( [a,b,c], [a,c], [a], [a,b,c,d], N, RESULT)
with the number of initial lists unknown at the beginning?
Using the univ operator ( =.. ) it would be possible to unify it with a list of terms and traversing it like every other list. But how to write the goal?
my_predicate(??) =.. [??]
I really don’t know if this is even possible..
you can define predicates with different arities that have the same name but they will be different predicates.
my suggestion is to change the encoding; instead of a number of initial lists, have a list of initial lists.
the other solution would be to write predicates for all the possible numbers of arguments (or dynamically generate them).