Selects clauses of the public user-defined predicates in the database. The first parameter must be the head of a clause which will be used for finding a match in the database, the second parameter is unified with the body of the user-defined predicate after the successful match of the first parameter. This predicate is re-executable as many times as there are matches for the Head parameter.
By specifying 'true' as the second parameter only facts will be unified with the first argument of clause/2. If the second parameter of clause/2 is an empty variable and a match is found with a fact the value 'true' will be unified with the empty variable.
see also: current_predicate/1 number_vars/3 freeze/2 melt/3 module encryption save_module/3
Suppose the database contains the following predicates:
| public. cat. elk(X) :- moose(X). |
| Example | |
| clause(elk(X), B). | the goal succeeds and the variable X will be an empty variable and B has the value 'moose(__4)' |
| clause(reverse(X, Y), B). | the goal succeeds twice with the following values: X = [] Y = [] B = true X = [__4 | __5] Y = __2 B = reverse(__9, __11), append(__11, [__8], __10) |
| clause(legs(X, Y, Z), B). | fails |
| clause(cat, true). | succeeds, the fact cat/0 is unified with the value of the first parameter which is 'cat' |
| clause(cat, T). | succeeds, the fact cat/0 is unified with the value of the
first parameter which is 'cat' and the empty variable is unified with the value 'true' T = true |
| Exceptions | |
| Head is a variable | an instantiation_error exception is thrown |
| Head is neither a variable nor a callable term | a type_error(callable, Head) exception is thrown |
| Body is neither a variable nor a callable term | a type_error(callable, Body) exception is thrown |
| The predicate indicator PredInd of Head is that of a private procedure | a permission_error(access, private_procedure, PredInd) exception is thrown |