Hypertext Markup "chap11a"

Admin User, erstellt 23. Aug. 2023
         
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<!--
Modern Albufeira Prolog Interpreter
Literate Programming
Warranty & Liability
To the extent permitted by applicable law and unless explicitly
otherwise agreed upon, XLOG Technologies AG makes no warranties
regarding the provided information. XLOG Technologies AG assumes
no liability that any problems might be solved with the information
provided by XLOG Technologies AG.
Rights & License
All industrial property rights regarding the information - copyright
and patent rights in particular - are the sole property of XLOG
Technologies AG. If the company was not the originator of some
excerpts, XLOG Technologies AG has at least obtained the right to
reproduce, change and translate the information.
Reproduction is restricted to the whole unaltered document.
Reproduction of the information is only allowed for non-commercial
uses. Selling, giving away or letting of the execution of the
library is prohibited. The library can be distributed as part of
your applications and libraries for execution provided this comment
remains unchanged.
Restrictions
Only to be distributed with programs that add significant and primary
functionality to the library. Not to be distributed with additional
software intended to replace any components of the library.
Trademarks
Jekejeke is a registered trademark of XLOG Technologies AG.
-->
<body>
<link rel="stylesheet" href="notebook.css" type="text/css">
<title editable="nocomment">Chap11a</title>
<h1>Chap11a: assertz</h1>
<p>Prolog has two database manipulation commands:
assertz and retract. Let’s see how these are used.
Suppose we start with an empty database. So if we
give the command:</p>
<table style="width: 100%">
<tr>
<td class="input" style="width: 100%"
contenteditable="true" id="text0" spellcheck="false"
>?- listing.
</td>
<td rowspan="2" valign="top">
<button class="run" id="launch0"
></button>
</td>
</tr>
<tr>
<td class="result" id="demo0"></td>
</tr>
</table>
<p>then Prolog will simply respond true; the listing (of course)
is empty.</p><p>Suppose we now give this command:<p>
<table style="width: 100%">
<tr>
<td class="input" style="width: 100%"
contenteditable="true" id="text1" spellcheck="false"
>?- assertz(happy(mia)).
</td>
<td rowspan="2" valign="top">
<button class="run" id="launch1"
></button>
</td>
</tr>
<tr>
<td class="result" id="demo1"></td>
</tr>
</table>
<p>This succeeds ( assertz/1 commands always succeed). But what is
important is not that it succeeds, but the side-effect it
has on the database. For if we now give the command</p>
<table style="width: 100%">
<tr>
<td class="input" style="width: 100%"
contenteditable="true" id="text2" spellcheck="false"
>?- listing.
</td>
<td rowspan="2" valign="top">
<button class="run" id="launch2"
></button>
</td>
</tr>
<tr>
<td class="result" id="demo2"></td>
</tr>
</table>
<p>We get the fact. That is, the database is no longer empty:
it now contains the fact we asserted.</p>
<p>Suppose we then made four more assert commands:</p>
<table style="width: 100%">
<tr>
<td class="input" style="width: 100%"
contenteditable="true" id="text3" spellcheck="false"
>?- assertz(happy(vincent)).
?- assertz(happy(marcellus)).
?- assertz(happy(butch)).
?- assertz(happy(vincent)).
</td>
<td rowspan="2" valign="top">
<button class="run" id="launch3"
></button>
</td>
</tr>
<tr>
<td class="result" id="demo3"></td>
</tr>
</table>
<p>and then ask for a listing:</p>
<table style="width: 100%">
<tr>
<td class="input" style="width: 100%"
contenteditable="true" id="text4" spellcheck="false"
>?- listing.
</td>
<td rowspan="2" valign="top">
<button class="run" id="launch4"
></button>
</td>
</tr>
<tr>
<td class="result" id="demo4"></td>
</tr>
</table>
<p>All the facts we asserted are now in the knowledge base.
Note that happy(vincent) is in the knowledge base twice.
As we asserted it twice, this seems sensible.</p>
<script type="module">
import {setup_engine, link_cells_async
} from "./engine.mjs";
setup_engine();
link_cells_async();
</script>
</body>
</html>