next up previous contents
Next: Using "it" to Up: CHAPTER.7: THE POP-11 Previous: MATCHing on a

Adding and removing database items

Since this facility is often required, Pop-11 provides a collection of automatically loaded library procedures for manipulating lists of lists. They all make use of a global variable `database' which may contain arbitrary information.

We can build up a DATABASE using ADD

    vars database;
    [] -> database;
    add([a]);
    add([b]);

    database =>
    ** [[b] [a]]
Notice that items appear in reverse order to the order of ADDing.

More concisely we can use ALLADD

    alladd([[c] [d]]);
    database =>
    ** [[d] [c] [b] [a]]
Complementing ADD and ALLADD we have REMOVE and ALLREMOVE.

    remove([c]);
    database =>
    **[[d] [b] [a]]
The order of items in a call of ALLREMOVE is not important i.e. it does not need to reflect the ordering of the DATABASE

    allremove([[a] [b] [d]]);
    database =>
    ** []
The procedure REMOVE will remove at most one item from the database, even if it is given a pattern which matches several. Thus REMOVE([==]); instead of removing everything, removes just one item. Moreover, REMOVE will generate a MISHAP if it does not find one item to remove. Similarly, ALLREMOVE will generate a mishap if it can't remove something for every element of the list of patterns given to it as argument.

The procedure FLUSH is provided without these restrictions. FLUSH deletes everything in the database that matches its argument, but if there is nothing that matches, then FLUSH does nothing!

The argument given to FLUSH is a pattern specification, that is FLUSH uses MATCHES to determine the list items that it will DELETE. It is however very powerful in its action... it removes ALL the matching DATABASE entries. Thus with the DATABASE [[D] [C] [B] [A]] the action

    flush([=]);
clears the DATABASE, thus:

    database =>
    ** []
Thus in this situation FLUSH([=]) is equivalent to:

    allremove([[a] [b] [c] [d]]);
Whenever the database contains only one-element lists, the command

    flush([=]);
will remove them all.

Similarly

    flush([==]);
will remove all lists from the database no matter what is in them. It is therefore equivalent to

    [] -> database;


Aaron Sloman
Fri Jan 2 03:17:44 GMT 1998