6.8 Queries


Queries are just like the body of a rule:

  • A query consists of one or more subgoals, separated by commas, and ended with a period:
    subgoal, subgoal, ..., subgoal.
  • For the query to succeed, all of its subgoals must be satisfied by matching.
  • This is done from right to left, in the order of the subgoals.

Queries are written in the Prolog+CG user interface, in the lower part of the main window.


A query always gives an answer. This can be:

  1. no.
    meaning that the query did not succeed.
  2. {}
    meaning "yes", or that the query did succeed and that there were no variable bindings.
  3. A set of variable bindings, meaning that the query succeeded with the given variable bindings. For example:

    {X = gr1, Y = [Animal]}
    {X = gr2, Y = [Human]}

PrevLite: 6.7 Matching
NextLite: 6.9 Lists

Prev: 6.7 Matching
Up: 6 Prolog for CG users
Next: 6.9 Lists