While rules are used to infer new knowledge or take action, queries are used to ask questions about a rule session.
Queries are typically defined with defquery, which has the following structure:
A query has two major pieces:
- A parameter definition, which allow callers to control the scope of the query when it is called.
- One or more conditions, which define the facts matching the query. These conditions are the same structure as a rule left-hand side.
A sample query looks like this:
A caller may then execute that query with arguments. So if we only wanted to find lunch promotions, we might perform the query like this:
Some queries may have no parameters. Queries return a sequence of results, with each result being a map of the a bound variable to its value. So the above query may return a sequence that looks like this:
- See the Writing Expressions section for details on writing expressions.