Flux
Flux

Reputation: 10920

How to get predicates by specifying the number of arguments it should have?

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:

  1. mypred(d, 2, Rel): Rel would be d(m, n), d(x, y), false.
  2. mypred(d, 3, Rel): Rel would be d(a, b, c), d(i, j, k), false.
  3. mypred(d, 4, Rel): Rel would be d(1, 2, 3, 4), false.

Upvotes: 1

Views: 48

Answers (1)

false
false

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 for many uses.

Upvotes: 1

Related Questions