How can I check if a predicate exists in a Prolog program? That would be an exists/1
, like:
?- exists(some_predicate).
false.
?- assert(some_predicate).
true.
?- exists(some_predicate).
true.
How can I check if a predicate exists in a Prolog program? That would be an exists/1
, like:
?- exists(some_predicate).
false.
?- assert(some_predicate).
true.
?- exists(some_predicate).
true.
You can use current_predicate/1, current_predicate/2 or predicate_property/2 (for the last you will probably need functor/3):
current_predicate/2
andpredicate_property/2
(with visible) succeeds if the predicate can be autoloaded whilecurrrent_predicate/1
failsthe 'old fashioned way', but accepted in ISO, is clause/2. You could encounter it while reusing/browsing some of the older examples.
example: