Skip to content

Commit

Permalink
edited prolog intro slides
Browse files Browse the repository at this point in the history
  • Loading branch information
Whitomtit committed Jul 22, 2024
1 parent eda27b9 commit 45fdb99
Showing 1 changed file with 0 additions and 91 deletions.
91 changes: 0 additions & 91 deletions Material/Tutorials/prolog/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,97 +226,6 @@ Also possible using brackets:
?- [prog].
```

<!--vert-->
### dynamic rules

You can add clauses dynamically:

```prolog
:- assertz(eats(bear, tuna)).
:- assertz((
mother(Child, Mother) :-
parent(Child, Mother),
female(Mother)
)).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

```prolog
?- eats(bear, tuna).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

`asserta` asserts the clause as first clause of the predicate while `assertz` asserts it as last clause.

<!--vert-->

### dynamic rules

Note that facts and rules from a compiled or loaded program are not dynamic by default, so you cannot add to them using assertions.

<!--vert-->

Dynamically remove a clause using `retract/1`:

```prolog
:- assertz(q(a)).
:- assertz((p(X) :- q(X))).
:- assertz(p(b)).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

```prolog
:- retract(p(X) :- q(a)).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

```prolog
?- p(a).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

<!--vert-->

Dynamically remove all clauses using `retractall/1`:

```prolog
:- assertz(q_2(a)).
:- assertz((p_2(X) :- q_2(X))).
:- assertz(p_2(b)).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

```prolog
:- retractall(p_2(_)).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

```prolog
?- p_2(a).
?- p_2(b).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

<!--vert-->

Dynamically remove a predicate using `abolish/1`:

```prolog
:- assertz(p(a)).
:- assertz(p(b)).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

```prolog
:- abolish(p/1).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

```prolog
?- p(X).
```
<!-- .element: data-thebe-executable-prolog data-language="text/x-prolog" -->

---

### matching
Expand Down

0 comments on commit 45fdb99

Please sign in to comment.