简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM