Clause retrival and information
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.
alice.tuprolog.PrologActionFixture |
start |
alice.tuprolog.EngineFixture |
enter |
theory |
:- dynamic(cat/0).
cat.
:- dynamic(dog/0).
dog :- true.
elk(X) :- moose(X).
:- dynamic(legs/2).
legs(A, 6) :- insect(A).
legs(A, 7) :- A, call(A).
:- dynamic(insect/1).
insect(ant).
insect(bee).
|
1. clause/2
clause(Head, Body)
is true iff:
- The predicate
Head
is public, and
- There is a clause in the database which corresponds to a term
H :- 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)
1.1 Example tests
Let's then ask the engine to solve a query against the database, and check variable bindings.
alice.tuprolog.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.
alice.tuprolog.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 |
true |
enter |
query |
clause(atom(_), Body). |
check |
hasSolution |
false |
check |
exception |
permission_error(access, private_procedure, atom/1) |
2. 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)
2.1 Example tests
Let's then ask the engine to solve a query against the database, and check variable bindings.
alice.tuprolog.PrologActionFixture |
enter |
query |
current_predicate(dog/0). |
check |
hasSolution |
true expected false actual |
enter |
query |
current_predicate(current_predicate/1). |
check |
hasSolution |
false |
enter |
query |
current_predicate(elk/Arity). |
check |
hasSolution |
true expected false actual |
enter |
variable |
Arity |
check |
binding |
1
alice.tuprolog.NoSolutionException at alice.tuprolog.SolveInfo.getVarValue(SolveInfo.java:181) at alice.tuprolog.EngineFixture.binding(EngineFixture.java:92) at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at fit.TypeAdapter.invoke(Unknown Source) at fit.TypeAdapter.get(Unknown Source) at fit.Fixture.check(Unknown Source) at alice.tuprolog.PrologActionFixture.check(PrologActionFixture.java:18) at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at fit.ActionFixture.doCells(Unknown Source) at fit.Fixture.doRow(Unknown Source) at fit.Fixture.doRows(Unknown Source) at fit.Fixture.doTable(Unknown Source) at fit.Fixture.interpretFollowingTables(Unknown Source) at fit.Fixture.interpretTables(Unknown Source) at fit.Fixture.doTables(Unknown Source) at alice.tuprolog.AcceptanceFixture.run(AcceptanceFixture.java:30) at alice.tuprolog.AcceptanceFixture.right(AcceptanceFixture.java:41) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at fit.TypeAdapter.invoke(Unknown Source) at fit.TypeAdapter.get(Unknown Source) at fit.Fixture.check(Unknown Source) at fit.ColumnFixture.check(Unknown Source) at fit.ColumnFixture.doCell(Unknown Source) at fit.Fixture.doCells(Unknown Source) at fit.Fixture.doRow(Unknown Source) at fit.ColumnFixture.doRow(Unknown Source) at alice.tuprolog.AcceptanceFixture.doRow(AcceptanceFixture.java:78) at fit.Fixture.doRows(Unknown Source) at fit.ColumnFixture.doRows(Unknown Source) at fit.Fixture.doTable(Unknown Source) at fit.Fixture.interpretTables(Unknown Source) at fit.Fixture.doTables(Unknown Source) at fit.FileRunner.process(Unknown Source) at fit.FileRunner.run(Unknown Source) at fit.FileRunner.main(Unknown Source)
|
enter |
query |
current_predicate(foo/A). |
check |
hasSolution |
false |
enter |
query |
current_predicate(Name/1). |
check |
hasSolution |
true expected false actual |
enter |
variable |
Name |
check |
binding |
elk
alice.tuprolog.NoSolutionException at alice.tuprolog.SolveInfo.getVarValue(SolveInfo.java:181) at alice.tuprolog.EngineFixture.binding(EngineFixture.java:92) at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at fit.TypeAdapter.invoke(Unknown Source) at fit.TypeAdapter.get(Unknown Source) at fit.Fixture.check(Unknown Source) at alice.tuprolog.PrologActionFixture.check(PrologActionFixture.java:18) at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at fit.ActionFixture.doCells(Unknown Source) at fit.Fixture.doRow(Unknown Source) at fit.Fixture.doRows(Unknown Source) at fit.Fixture.doTable(Unknown Source) at fit.Fixture.interpretFollowingTables(Unknown Source) at fit.Fixture.interpretTables(Unknown Source) at fit.Fixture.doTables(Unknown Source) at alice.tuprolog.AcceptanceFixture.run(AcceptanceFixture.java:30) at alice.tuprolog.AcceptanceFixture.right(AcceptanceFixture.java:41) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at fit.TypeAdapter.invoke(Unknown Source) at fit.TypeAdapter.get(Unknown Source) at fit.Fixture.check(Unknown Source) at fit.ColumnFixture.check(Unknown Source) at fit.ColumnFixture.doCell(Unknown Source) at fit.Fixture.doCells(Unknown Source) at fit.Fixture.doRow(Unknown Source) at fit.ColumnFixture.doRow(Unknown Source) at alice.tuprolog.AcceptanceFixture.doRow(AcceptanceFixture.java:78) at fit.Fixture.doRows(Unknown Source) at fit.ColumnFixture.doRows(Unknown Source) at fit.Fixture.doTable(Unknown Source) at fit.Fixture.interpretTables(Unknown Source) at fit.Fixture.doTables(Unknown Source) at fit.FileRunner.process(Unknown Source) at fit.FileRunner.run(Unknown Source) at fit.FileRunner.main(Unknown Source)
|
check |
hasAnotherSolution |
true expected false actual |
check |
binding |
insect
alice.tuprolog.NoSolutionException at alice.tuprolog.SolveInfo.getVarValue(SolveInfo.java:181) at alice.tuprolog.EngineFixture.binding(EngineFixture.java:92) at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at fit.TypeAdapter.invoke(Unknown Source) at fit.TypeAdapter.get(Unknown Source) at fit.Fixture.check(Unknown Source) at alice.tuprolog.PrologActionFixture.check(PrologActionFixture.java:18) at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at fit.ActionFixture.doCells(Unknown Source) at fit.Fixture.doRow(Unknown Source) at fit.Fixture.doRows(Unknown Source) at fit.Fixture.doTable(Unknown Source) at fit.Fixture.interpretFollowingTables(Unknown Source) at fit.Fixture.interpretTables(Unknown Source) at fit.Fixture.doTables(Unknown Source) at alice.tuprolog.AcceptanceFixture.run(AcceptanceFixture.java:30) at alice.tuprolog.AcceptanceFixture.right(AcceptanceFixture.java:41) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at fit.TypeAdapter.invoke(Unknown Source) at fit.TypeAdapter.get(Unknown Source) at fit.Fixture.check(Unknown Source) at fit.ColumnFixture.check(Unknown Source) at fit.ColumnFixture.doCell(Unknown Source) at fit.Fixture.doCells(Unknown Source) at fit.Fixture.doRow(Unknown Source) at fit.ColumnFixture.doRow(Unknown Source) at alice.tuprolog.AcceptanceFixture.doRow(AcceptanceFixture.java:78) at fit.Fixture.doRows(Unknown Source) at fit.ColumnFixture.doRows(Unknown Source) at fit.Fixture.doTable(Unknown Source) at fit.Fixture.interpretTables(Unknown Source) at fit.Fixture.doTables(Unknown Source) at fit.FileRunner.process(Unknown Source) at fit.FileRunner.run(Unknown Source) at fit.FileRunner.main(Unknown Source)
|
The remaining tests cover the cases when an error or exception is thrown by the engine while solving a query.
alice.tuprolog.PrologActionFixture |
enter |
query |
current_predicate(4). |
check |
hasSolution |
false |
check |
exception |
type_error(predicate_indicator, 4) |
Run the tests!
The results of the tests for Clause retrival and information are as follows:
fit.Summary |
counts |
18 right, 6 wrong, 5 ignored, 3 exceptions |
run date |
Mon Jul 14 20:33:39 CEST 2014 |
run elapsed time |
0:00.06 |