Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog: How to check if a predicate exists?

Tags:

prolog

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.
like image 989
vmassuchetto Avatar asked Oct 14 '12 20:10

vmassuchetto


People also ask

Why not predicate is used in Prolog?

Prolog in Artificial Intelligence The not predicate is used to negate some statement, which means, when a statement is true, then not(statement) will be false, otherwise if the statement is false, then not(statement) will be true. If X and Y match, then different(X,Y) fails, Otherwise different(X,Y) succeeds.

What is built in predicate in Prolog?

This predicate is used to make a list of all solutions X, from the predicate P. The returned list will be L. So we will read this as “find all of the Xs, such that X is a solution of predicate P and put the list of results in L”. Here this predicate stores the results in the same order, in which Prolog finds them.

Is Prolog a predicate?

Prolog predicate is the method to contain the argument and return the boolean values such as true or false. It is a function to operate and return given values, variables, or arguments using a prolog programming language.


1 Answers

You can use current_predicate/1, current_predicate/2 or predicate_property/2 (for the last you will probably need functor/3):

?- current_predicate(a/1).
false.

?- functor(A,a,1),predicate_property(A,visible).
false.

?- functor(A,a,1),current_predicate(_,A).
false.

?- assert(a(42)).
true.

?- current_predicate(a/1).
true.

?- functor(A,a,1),predicate_property(A,visible).
A = a(_G136).

?- functor(A,a,1),current_predicate(_,A).
A = a(_G122).

current_predicate/2 and predicate_property/2 (with visible) succeeds if the predicate can be autoloaded while currrent_predicate/1 fails

like image 92
Thanos Tintinidis Avatar answered Oct 16 '22 05:10

Thanos Tintinidis