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

Querying facts

The following database represents a simple recipe for making a vinaigrette sauce, formulated as Prolog facts.

ingredient(vinaigrette,vinegar).
ingredient(vinaigrette,oil).
ingredient(vinaigrette,salt).
ingredient(vinaigrette,pepper).
ingredient(vinaigrette,mustard).
mix(vinaigrette,salt,pepper,mixture1,by_shaking).
mix(vinaigrette,mustard,mixture1,mixture2,by_stirring).
mix(vinaigrette,vinegar,mixture2,mixture3,by_stirring).
mix(vinaigrette,oil,mixture3,mixture4,by_stirring_dropwise).

Queries to the database might be of various kinds:

The second technique, using variables, permits very flexible database querying, in which one or indeed all possible correct matches can be found. Query results such as the following can be achieved:

  1. ingredient(vinaigrette,mustard).
    yes
  2. ingredient(vinaigrette,What).
    vinegar oil salt pepper mustard
  3. ingredient(Recipe,mustard).
    vinaigrette
  4. mix(A,B,C,D,Mix_Styles).
    by_shaking by_shaking by_stirring by_stirring by_stirring_dropwise


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