Skip to content
EN FR

Queries and quantifiers

Documentation status: reference — see Maturity and evidence.

H-Logic queries operate on conceptual structures rather than storage tables. The query expression says what is sought; the return expression defines the result projection.

Query forms

ask .:#A(x) and .:#R(x, y) return x;

? .:#Person(Tom)[name='Tom Hanks']
  and .:#like(Tom, Anne)
  return (Tom, Anne);

Free roles in the target expression form the query environment. Do not declare a prefixed variable list such as ?x := ....

Quantifiers

exists y:#B on .:#R(y);
every y:#B on .:#R(y);
any x:#A, exists y:#B on .:#Pair(x, y);

exists requires at least one matching value. every constrains all values associated through the target relation. any establishes a source domain for the following pattern.

A quantified variable may have a type restriction or an equality binding, but the compact combined form y:#A=&a is not valid. Write the intended constraint explicitly.

Logical composition

Patterns can be composed with and, or, arithmetic expressions and relational operators. Naming a relation occurrence lets a query return or further constrain the fact itself, not only its participants.

Query returning a command

A query may return a conceptual command:

ask .:#A(me, name, context) and (name='toto')
return do _:#love(me, #you, context);

Use this form when a governed condition and the conceptual operation it enables should remain inspectable in the same language.