Queries look like facts, but are presented on standard input.
Each query in the rule RHS is then tried in order, left to right, finding new settings for more rule variables, or reporting that the query cannot be satisfied. If some RHS query cannot be satisfied, the next rule for this predicate name is tried. Once the last RHS query is successfully satisfied, the original query is reported satisfied, along with satisfying values for any variables appearing in that query. Such a function remembers if it has been called before with the same arguments, and if so, just returns the result it got previously, without doing any further recursive search. This changes an exponential-time program for Fibbonacci number calculation to one that runs in linear time, because the matching of a query against a data base rule head can be done using a hash table, essentially in unit time.