next up previous contents
Next: Retrieving values from Up: CHAPTER.7: THE POP-11 Previous: Finding items in

Using "it" to record what was matched

The value returned by present when successful is TRUE. But that does not determine what exactly matched the pattern in the database. For many purposes however we will need to know what the matched item is for example to use it in the THEN branch of the conditional. For this purpose the DATABASE variable IT is set to have the value of the matching item, when PRESENT finds something.

    alladd([[a b c d] [d c b a] [a b d c]]);

    if present([== b ==]) then
      it =>
      remove(it);
    endif;
    ** [a b c d]
Thus we see that the item matched, and subsequently removed was the first item in the database.

Note that it found only ONE item, matching the pattern, and removed it. FOREACH, explained below, shows how you can search for ALL items matching some pattern.



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