Prolog "chap11b"

Admin User, erstellt 26. Mai 2023
         
/**
* <title editable="nocomment">Chap11b</title>
* <h1>Chap11b: retract</h1>
* <p>The database manipulations we have been making have
* changed the meaning of the predicate happy/1 . More generally,
* database manipulation commands give us the ability to change
* the meaning of predicates while we are running programs.
* Predicates whose definitions change during run-time are
* called dynamic predicates, as opposed to the static predicates
* that we have previously dealt with. Most Prolog interpreters
* insist that we explicitly declare the predicates that we wish
* to be dynamic. We will soon examine an example involving dynamic
* predicates, but let’s first complete our discussion of the
* database manipulation commands.</p>
* <p>Now that we know how to assert new information into the database,
* we should also learn how to remove information when we no longer
* need it. There is an inverse predicate to assertz/1 , namely retract/1 .
* For example, if we carry straight on from the previous example by
* giving the command:</p>
*/
:- dynamic happy/1.
happy(mia).
happy(vincent).
happy(marcellus).
happy(butch).
happy(vincent).
?- retract(happy(marcellus)).
/**
* <p>and then list the database, we get:</p>
*/
?- listing.
/**
* <p>That is, the fact happy(marcellus) has been removed.</p>
* <p>Suppose we go on further, and say</p>
*/
?- once(retract(happy(vincent))).
/**
* <p>and then ask for a listing. We get:</p>
*/
?- listing.
/**
* <p>Note that the first occurrence of happy(vincent) , and only the
* first occurrence, was removed.</p>
* <p>To remove all of our assertions contributing to the definition of
* the predicate happy/1 we can use a variable:</p>
*/
?- retract(happy(X)).
/**
* <p>A listing reveals that the database is now empty.</p>
*/
?- listing.