’and’ and ’or’

While we recommended against using the , (comma) operator in facts, in queries (and rules, see Rules), it is commonly done.

The , symbol should be read as “and”. Similarly, there is a ; (semi-colon) operator, which means “or”. There are also the two alternative forms: \and and \or. \or and ; cannot be used in facts or in the heads of rules (see Rules).

As an example, we can ask about Louisa’s grandparents using either form of “and”:

@!{'Who are Louisas grandparents?'(?Grandparent)} !-
  Louisa [ parent -> ?p ] , ?p [ parent -> ?Grandparent ].
@!{'Who are Louisas grandparents?'(?Grandparent)} !-
  Louisa [ parent -> ?p ] \and ?p [ parent -> ?Grandparent ].

If you start to write queries with many \ands, you may consider whether it makes sense to instead define a new property which uses a rule (see Rules), and simply query the defined property.

At this point, you may wonder about the “not” operator, and perhaps “exists” and “forall”. These issues are discussed later, in Negation and Quantifiers.