Reputation: 10920
Suppose I have these relations:
d(m, n).
d(x, y).
d(a, b, c).
d(i, j, k).
d(1, 2, 3, 4).
How can I write a predicate mypred(Pred, NumArgs, Rel)
?
Examples:
mypred(d, 2, Rel)
: Rel
would be d(m, n)
, d(x, y)
, false
.mypred(d, 3, Rel)
: Rel
would be d(a, b, c)
, d(i, j, k)
, false
.mypred(d, 4, Rel)
: Rel
would be d(1, 2, 3, 4)
, false
.Upvotes: 1
Views: 48
Reputation: 10102
mypred(F, A, Rel_0) :-
functor(Rel_0, F, A),
call(Rel_0).
However, rather don't use such a definition. Instead try to use call/N
with N > 1
.
Definitions as mypred/3, are very difficult to analyze. Cross-referencing is practically impossible. On the other hand, with call/N, N > 1
quite similar functionality is possible, cross-referencing stays intact. See meta-predicate for many uses.
Upvotes: 1