user5464136
user5464136

Reputation:

Comparing a variable and a predicate in Prolog

I want to check if a variable, say X, is a predicate of the form add(). How do I check if this is true? X == add() does not work, neither does X is add(_). How can I achieve this comparison?

Upvotes: 0

Views: 189

Answers (1)

false
false

Reputation: 10102

The general, generic way to do so is:

Specific = add(_), ..., subsumes_term(add(_Any), Specific).

Often, people will optimize this to:

Specific = add(_), ..., nonvar(Specific), Specific = add(_).

But in the general case, you will need subsumes_term/2

Upvotes: 2

Related Questions