Skip to content

Commit 02f57e0

Browse files
authored
Merge pull request #788 from axone-protocol/feat/predicates-v13.0.1
📜 Add v13.0.1 predicates documentation version
2 parents 81c8e56 + f159a5f commit 02f57e0

38 files changed

Lines changed: 2876 additions & 0 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
[//]: # (This file is auto-generated. Please do not modify it yourself.)
5+
6+
# abolish/1
7+
8+
## Description
9+
10+
`abolish/1` is a predicate that abolishes a predicate from the database. Removes all clauses of the predicate designated by given predicate indicator Name/Arity.
11+
12+
## Signature
13+
14+
```text
15+
abolish(+PredicateIndicator)
16+
```
17+
18+
Where:
19+
20+
- PredicateIndicator is the indicator of the predicate to abolish.
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
[//]: # (This file is auto-generated. Please do not modify it yourself.)
5+
6+
# asserta/1
7+
8+
## Description
9+
10+
`asserta/1` is a predicate that asserts a clause into the database as the first clause of the predicate.
11+
12+
## Signature
13+
14+
```text
15+
asserta(+Clause)
16+
```
17+
18+
Where:
19+
20+
- Clause is the clause to assert into the database.
21+
22+
## Examples
23+
24+
### Assert a fact into the database
25+
26+
This scenario demonstrates the process of asserting a new fact into a Prolog database. In Prolog, asserting a fact means
27+
adding a new piece of information or *knowledge* into the database, allowing it to be referenced in subsequent queries.
28+
This is particularly useful when you want to dynamically extend the knowledge base with facts or rules based on conditions
29+
or interactions during runtime.
30+
31+
Here are the steps of the scenario:
32+
33+
- **Given** the program:
34+
35+
``` prolog
36+
assert_fact :- asserta(father(john, pete)).
37+
```
38+
39+
- **Given** the query:
40+
41+
``` prolog
42+
assert_fact, father(X, Y).
43+
```
44+
45+
- **When** the query is run
46+
- **Then** the answer we get is:
47+
48+
``` yaml
49+
height: 42
50+
gas_used: 3977
51+
answer:
52+
has_more: false
53+
variables: ["X", "Y"]
54+
results:
55+
- substitutions:
56+
- variable: X
57+
expression: john
58+
- variable: 'Y'
59+
expression: pete
60+
```
61+
62+
### Only dynamic predicates can be asserted
63+
64+
This scenario demonstrates that only dynamic predicates can be asserted. In Prolog, dynamic predicates are those that can be
65+
modified during runtime. This is in contrast to static predicates, which are fixed and cannot be modified.
66+
67+
Here are the steps of the scenario:
68+
69+
- **Given** the program:
70+
71+
``` prolog
72+
parent(jane, alice).
73+
```
74+
75+
- **Given** the query:
76+
77+
``` prolog
78+
asserta(parent(john, alice)).
79+
```
80+
81+
- **When** the query is run
82+
- **Then** the answer we get is:
83+
84+
``` yaml
85+
height: 42
86+
gas_used: 3975
87+
answer:
88+
has_more: false
89+
results:
90+
- error: "error(permission_error(modify,static_procedure,parent/2),asserta/1)"
91+
```
92+
93+
### Show that the fact is asserted at the beginning of the database
94+
95+
This scenario demonstrates that the asserta/1 predicate adds the fact to the beginning of the database. This means that
96+
the fact is the first fact to be matched when a query is run.
97+
98+
This is in contrast to the assertz/1 predicate, which adds the fact to the end of the database.
99+
100+
Here are the steps of the scenario:
101+
102+
- **Given** the program:
103+
104+
``` prolog
105+
:- dynamic(parent/2).
106+
107+
parent(jane, alice).
108+
109+
assert_fact :- asserta(parent(john, alice)).
110+
```
111+
112+
- **Given** the query:
113+
114+
``` prolog
115+
assert_fact, parent(X, alice).
116+
```
117+
118+
- **When** the query is run (limited to 2 solutions)
119+
- **Then** the answer we get is:
120+
121+
``` yaml
122+
height: 42
123+
gas_used: 3977
124+
answer:
125+
has_more: false
126+
variables: ["X"]
127+
results:
128+
- substitutions:
129+
- variable: X
130+
expression: john
131+
- substitutions:
132+
- variable: X
133+
expression: jane
134+
```
135+
136+
### Shows a simple counter example
137+
138+
This scenario demonstrates a simple counter example using the `asserta/1` and `retract/1` predicates.
139+
In this example, we represent the value of the counter as a dynamic predicate `counter/1` that is asserted and retracted
140+
to each time the value of the counter is incremented or decremented.
141+
142+
Here are the steps of the scenario:
143+
144+
- **Given** the program:
145+
146+
``` prolog
147+
:- dynamic(counter/1).
148+
149+
counter(0).
150+
151+
increment_counter :- retract(counter(X)), Y is X + 1, asserta(counter(Y)).
152+
decrement_counter :- retract(counter(X)), Y is X - 1, asserta(counter(Y)).
153+
```
154+
155+
- **Given** the query:
156+
157+
``` prolog
158+
counter(InitialValue), increment_counter, increment_counter, counter(IncrementedValue), decrement_counter, counter(DecrementedValue).
159+
```
160+
161+
- **When** the query is run
162+
- **Then** the answer we get is:
163+
164+
``` yaml
165+
height: 42
166+
gas_used: 3989
167+
answer:
168+
has_more: false
169+
variables: ["InitialValue", "IncrementedValue", "DecrementedValue"]
170+
results:
171+
- substitutions:
172+
- variable: InitialValue
173+
expression: 0
174+
- variable: IncrementedValue
175+
expression: 2
176+
- variable: DecrementedValue
177+
expression: 1
178+
```
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
sidebar_position: 3
3+
---
4+
[//]: # (This file is auto-generated. Please do not modify it yourself.)
5+
6+
# assertz/1
7+
8+
## Description
9+
10+
`assertz/1` is a predicate that asserts a clause into the database as the last clause of the predicate.
11+
12+
## Signature
13+
14+
```text
15+
assertz(+Clause)
16+
```
17+
18+
Where:
19+
20+
- Clause is the clause to assert into the database.
21+
22+
## Examples
23+
24+
### Assert a fact into the database
25+
26+
This scenario demonstrates the process of asserting a new fact into a Prolog database. In Prolog, asserting a fact means
27+
adding a new piece of information or *knowledge* into the database, allowing it to be referenced in subsequent queries.
28+
This is particularly useful when you want to dynamically extend the knowledge base with facts or rules based on conditions
29+
or interactions during runtime.
30+
31+
Here are the steps of the scenario:
32+
33+
- **Given** the program:
34+
35+
``` prolog
36+
assert_fact :- assertz(father(john, pete)).
37+
```
38+
39+
- **Given** the query:
40+
41+
``` prolog
42+
assert_fact, father(X, Y).
43+
```
44+
45+
- **When** the query is run
46+
- **Then** the answer we get is:
47+
48+
``` yaml
49+
height: 42
50+
gas_used: 3977
51+
answer:
52+
has_more: false
53+
variables: ["X", "Y"]
54+
results:
55+
- substitutions:
56+
- variable: X
57+
expression: john
58+
- variable: 'Y'
59+
expression: pete
60+
```
61+
62+
### Only dynamic predicates can be asserted
63+
64+
This scenario demonstrates that only dynamic predicates can be asserted. In Prolog, dynamic predicates are those that can be
65+
modified during runtime. This is in contrast to static predicates, which are fixed and cannot be modified.
66+
67+
Here are the steps of the scenario:
68+
69+
- **Given** the program:
70+
71+
``` prolog
72+
parent(jane, alice).
73+
```
74+
75+
- **Given** the query:
76+
77+
``` prolog
78+
assertz(parent(john, alice)).
79+
```
80+
81+
- **When** the query is run
82+
- **Then** the answer we get is:
83+
84+
``` yaml
85+
height: 42
86+
gas_used: 3975
87+
answer:
88+
has_more: false
89+
results:
90+
- error: "error(permission_error(modify,static_procedure,parent/2),assertz/1)"
91+
```
92+
93+
### Show that the fact is asserted at the end of the database
94+
95+
This scenario demonstrates that the assertz/1 predicate adds the fact to the end of the database. This means that
96+
the fact is the last fact to be matched when a query is run.
97+
98+
This is in contrast to the asserta/1 predicate, which adds the fact to the beginning of the database.
99+
100+
Here are the steps of the scenario:
101+
102+
- **Given** the program:
103+
104+
``` prolog
105+
:- dynamic(parent/2).
106+
107+
parent(jane, alice).
108+
109+
assert_fact :- assertz(parent(john, alice)).
110+
```
111+
112+
- **Given** the query:
113+
114+
``` prolog
115+
assert_fact, parent(X, alice).
116+
```
117+
118+
- **When** the query is run (limited to 2 solutions)
119+
- **Then** the answer we get is:
120+
121+
``` yaml
122+
height: 42
123+
gas_used: 3977
124+
answer:
125+
has_more: false
126+
variables: ["X"]
127+
results:
128+
- substitutions:
129+
- variable: X
130+
expression: jane
131+
- substitutions:
132+
- variable: X
133+
expression: john
134+
```
135+
136+
### Add and remove items in an inventory
137+
138+
This scenario demonstrates how to maintain a dynamic list of items (like in an inventory system) by representing each item
139+
as a fact in the Prolog knowledge base. By using dynamic predicates, we can add items to the inventory and remove them on demand.
140+
141+
Here are the steps of the scenario:
142+
143+
- **Given** the program:
144+
145+
``` prolog
146+
:- dynamic(inventory/1).
147+
148+
add_item(Item) :- assertz(inventory(Item)).
149+
remove_item(Item) :- retract(inventory(Item)).
150+
```
151+
152+
- **And** the query:
153+
154+
``` prolog
155+
add_item('apple'),
156+
add_item('banana'),
157+
add_item('orange'),
158+
remove_item('banana'),
159+
findall(I, inventory(I), CurrentInventory).
160+
```
161+
162+
- **When** the query is run
163+
- **Then** the answer we get is:
164+
165+
``` yaml
166+
height: 42
167+
gas_used: 3984
168+
answer:
169+
has_more: false
170+
variables: ["I","CurrentInventory"]
171+
results:
172+
- substitutions:
173+
- variable: CurrentInventory
174+
expression: "[apple,orange]"
175+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
[//]: # (This file is auto-generated. Please do not modify it yourself.)
5+
6+
# atomic_list_concat/2
7+
8+
## Description
9+
10+
`atomic_list_concat/2` is a predicate that unifies an Atom with the concatenated elements of a List.
11+
12+
## Signature
13+
14+
```text
15+
atomic_list_concat(+List, ?Atom)
16+
```
17+
18+
where:
19+
20+
- List is a list of strings, atoms, integers, floating point numbers or non\-integer rationals
21+
- Atom is an Atom representing the concatenation of the elements of List

0 commit comments

Comments
 (0)