These predicates enable the database to be altered during execution.
asserta/1asserta(Clause) is true.
Templates and modes for the predicate are as follows:
asserta(@clause)
The examples defined in this subsection assume the database has been created from the following Prolog text.
| Goal | Theory | success(String goal,String theory) |
|---|---|---|
| asserta(legs(octopus, 8)). | :- dynamic(legs/2). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). | true |
| asserta((legs(A, 4) :- animal(A))). | :- dynamic(legs/2). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). | true |
| asserta((foo(X) :- X, call(X))). | :- dynamic(legs/2). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). | true |
Tests With Exception
| Goal | Theory | success(String goal) | Type Of Error |
|---|---|---|---|
| asserta(_). | :- dynamic(legs/2). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). | true | |
| asserta(4). | :- dynamic(legs/2). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). | true | |
| asserta((foo :- 4)). | :- dynamic(legs/2). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). | true | |
| asserta((atom(_) :- true)). | :- dynamic(legs/2). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). | true |
assertz/1assertz(Clause) is true.
Templates and modes for the predicate are as follows:
assertz(@clause)
The examples defined in this subsection assume the database has been created from the following Prolog text.
| Goal | Theory | success(String goal,String theory) |
|---|---|---|
| assertz(legs(spider, 8)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). | true |
| assertz((legs(B, 2) :- bird(B))). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). | true |
| assertz((foo(X) :- X -> call(X))). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). | true |
Tests With Exception
| Goal | Theory | success(String goal) | Type Of Error |
|---|---|---|---|
| assertz(_). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). | true | |
| assertz(4). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). | true | |
| assertz((foo :- 4)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). | true | |
| assertz((atom(_) :- true)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). | true |
retract/1retract(Clause) is true iff the database contains at least one dynamic procedure with a clause Clause which unifies with Head :- Body.
retract(Clause) is re-executable.
Templates and modes for the predicate are as follows:
retract(+clause)
The examples defined in this subsection assume the database has been created from the following Prolog text.
| Goal | Theory | success(String goal,String theory) |
|---|---|---|
| retract(legs(octopus, 8)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | true |
| retract((foo(C) :- A -> B)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | true |
| Goal | Theory | success(String goal,String theory) |
|---|---|---|
| retract(legs(spider, 6)). | null | false |
| retract(insect(I)), write(I), retract(insect(bee)), fail. | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | false |
| retract((foo(A) :- A, call(A))). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | false |
Tests With Exception
| Goal | Theory | success(String goal) | Type Of Error |
|---|---|---|---|
| retract(insect(I)), write(I), retract(insect(bee)), fail. | null | true | |
| retract((X :- in_eec(Y))). | null | true | |
| retract((4 :- X)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | true | |
| retract((atom(X) :- X == '[]')). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | true |
| Goal | Theory | Variable | Solution | success(String goal,String theory,String variable,Strng solution) |
|---|---|---|---|---|
| retract((legs(X, 2) :- T)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | T | bird(X) | true |
| retract((legs(X, Y) :- Z)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | Y | 2 | true |
| retract((legs(X, Y) :- Z)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | Z | animal(X) | true |
| retract((legs(X, Y) :- Z)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | Y | 6 | true |
| retract((legs(X, Y) :- Z)). | :- dynamic(legs/2). legs(A, 4) :- animal(A). legs(octopus, 8). legs(A, 6) :- insect(A). legs(spider, 8). legs(B, 2) :- bird(B). :- dynamic(insect/1). insect(ant). insect(bee). :- dynamic(foo/1). foo(X) :- call(X), call(X). foo(X) :- call(X) -> call(X). | Z | insect(X) | true |
abolish/1abolish(Pred) is true.
Templates and modes for the predicate are as follows:
abolish(@predicate_indicator)
Let's start with some simple tests verifying success of failure of single goals.
| Goal | Theory | success(String goal,String theory) |
|---|---|---|
| abolish(foo/2). | null | true |
| Goal | Theory | success(String goal) | Type Of Error |
|---|---|---|---|
| abolish(foo/_). | null | true | |
| abolish(foo). | null | true | |
| abolish(foo(_)). | null | true | |
| abolish(abolish/1). | null | true |