How to invoke a predicate functor based on a variable instead of a name

Viewed 401

Let's say I've declared predicates a and c as follows:

a(b).

c(D, E) :- D(E).

I'd like to believe that c(a, b) succeeds, as D(E) matches a(b) if D is bound to a and E is bound to b, but (in SWI Prolog anyway) syntax checking is looking for an operator following D in the definition of c, so apparently there's a rule that unification binds variables only to arguments, not functors. Is there some trick for asking the question posed by c, in which the identity of a predicate is one of the unknowns?

1 Answers

You can make use of call/2 predicate [swi-doc] to call a predicate with the given name and parameters. So your c/2 predicate is equivalent to call/2:

c(D, E) :-
    call(D, E).
Related