One of the most commonly used procedures is PRESENT, which takes a pattern and returns true or false depending on whether there is something in the database that matches the pattern. If the pattern contains variables preceded by "?" or "??", and the match is true, then the values of those variables will give information about the list that matched the pattern. For example:
alladd([ [the big red box] [the long square pole][the tiny blue flea]]) vars x y;
present([the ?x ?y pole]) => ** <true> x, y => ** long square
Exercise: what will the values of x and y be after
present([the ?x ?y flea]) =>
It does this by trying to MATCH the pattern against every item in the database. If the match is ever successful then true is returned as the result of PRESENT, otherwise the result is false.
alladd([[a b c d] [d c b a] [a b d c]]); present([== b ==]) => ** <true> present ([== b c]) => ** <false>Notice that PRESENT finds the `first' matching item.
PRESENT is frequently employed in a conditional e.g.
if present(pattern) then actionThe `IF... THEN' construction `uses up' the boolean value returned before THEN ie. try:
if present([== b ==]) then => endif;The "STACK EMPTY" error message arises because Pop-11 treats the value returned by PRESENT between "IF" and "THEN" as <TRUE> or <FALSE>. So the value is no longer there for "=>" to print out, and that produces the error message.