These predicates enable the contents of the database to be inspected during execution.
The examples provided for these predicates assume the database has been created from the following Prolog theory.
jTrolog.engine.PrologActionFixture | ||
start | jTrolog.engine.EngineFixture | |
enter | theory |
:- dynamic(cat/0).
:- dynamic(dog/0). elk(X) :- moose(X).
:- dynamic(legs/2).
:- dynamic(insect/1). |
clause/2
clause(Head, Body)
is true iff:
Head
is public, andH :- B
which unifies with Head :- Body
.clause(Head, Body)
is re-executable.
Note that the process of converting a clause to a term produces a renamed copy of the term H :- B
corresponding to the clause.
Templates and modes for the predicate are as follows:
clause(+head, ?callable_term)
Let's then ask the engine to solve a query against the database, and check variable bindings.
jTrolog.engine.PrologActionFixture | ||
enter | query | clause(cat, true). |
check | hasSolution | true |
enter | query | clause(dog, true). |
check | hasSolution | true |
enter | query | clause(legs(I, 6), Body). |
check | hasSolution | true |
enter | variable | Body |
check | binding | insect(I) expected insect(I) actual |
enter | query | clause(legs(C, 7), Body). |
check | hasSolution | true |
enter | variable | Body |
check | binding | (call(C), call(C)) expected C, call(C) actual |
enter | query | clause(insect(I), T). |
check | hasSolution | true |
enter | variable | I |
check | binding | ant |
enter | variable | T |
check | binding | true |
check | hasAnotherSolution | true |
enter | variable | I |
check | binding | bee |
enter | variable | T |
check | binding | true |
enter | query | clause(x, Body). |
check | hasSolution | false |
enter | query | clause(legs(A, 6), insect(f(A))). |
check | hasSolution | false |
The remaining tests cover the cases when an error or exception is thrown by the engine while solving a query.
jTrolog.engine.PrologActionFixture | ||
enter | query | clause(_, B). |
check | hasSolution | false |
check | exception | instantiation_error |
enter | query | clause(4, X). |
check | hasSolution | false |
check | exception | type_error(callable, 4) |
enter | query | clause(elk(N), Body). |
check | hasSolution | false expected true actual |
check | exception | permission_error(access, private_procedure, elk/1) expected type_error(callable, 4) actual |
enter | query | clause(atom(_), Body). |
check | hasSolution | false |
check | exception | permission_error(access, private_procedure, atom/1) expected permission_error(access, static_procedure, atom/1) actual |
current_predicate/1
current_predicate(PI)
is true iff PI
is a predicate indicator for one of the user-defined procedures in the database.
current_predicate(PI)
is re-executable.
Note that all user-defined procedures are found, whether static or dynamic. A user-defined procedure is also found even when it has no clauses. A user-defined procedure is not found if it has been abolished.
Templates and modes for the predicate are as follows:
current_predicate(?predicate_indicator)
Let's then ask the engine to solve a query against the database, and check variable bindings.
jTrolog.engine.PrologActionFixture | ||
enter | query | current_predicate(dog/0). |
check | hasSolution | true |
enter | query | current_predicate(current_predicate/1). |
check | hasSolution | false |
enter | query | current_predicate(elk/Arity). |
check | hasSolution | true |
enter | variable | Arity |
check | binding | 1 |
enter | query | current_predicate(foo/A). |
check | hasSolution | false |
enter | query | current_predicate(Name/1). |
check | hasSolution | true |
enter | variable | Name |
check | binding | elk |
check | hasAnotherSolution | true |
check | binding | insect |
The remaining tests cover the cases when an error or exception is thrown by the engine while solving a query.
jTrolog.engine.PrologActionFixture | ||
enter | query | current_predicate(4). |
check | hasSolution | false |
check | exception | type_error(predicate_indicator, 4) expected permission_error(access, static_procedure, atom/1) actual |
The results of the tests for Clause retrival and information are as follows:
fit.Summary | |
counts | 26 right, 6 wrong, 0 ignored, 0 exceptions |
run date | Tue Jan 15 12:14:14 CET 2008 |
run elapsed time | 0:00.07 |