next up previous contents
Next: Implementing queries with variables Up: Prolog: queries and rules Previous: Rules

Implementing queries with constants

There are two basic ways of formulating and querying databases in Prolog:

  1. By asserting facts and rules from the keyboard within the interpreter environment, and entering query statements from the keyboard.
  2. By writing facts and rules and query statements in a file, and consulting the file with the interpreter.

The second technique is usually more convenient. A simple file for the `mustard' example is:

condiment(mustard).

spice(X) :- condiment(X).

:- spice(X),write(X),nl,halt.

The `wh'-type query is prefixed by the operator `:-', and the variable is written to standard output (usually the monitor) by the `write' predicate, followed by another writing predicate, `nl', which starts a new line.



Dafydd Gibbon
Fri Nov 28 02:24:58 MET 1997