Program

A Datalog program consists of a set of facts that comprise the extensional database, a list of rules that are used to infer relations in the intensional database, and possibly a set of queries to interrogate the result of any reasoning performed over the program.

To be able to facilitate interchange a DATALOG-TEXT resource also includes processing instructions that provide the parser and resolver information on how to interpret the contents of the resource1.

program

program ::= processing-instruction* ( fact | rule | query )* ;

A program consists of a single file containing facts, rules, and queries as well as any additional files referenced via § Processing Instructions.

Example

The following program is an encoding of the classical syllogism “all men are mortal, Socrates is a man, therefore Socrates is mortalMill1851.

1: .assert human(string).
2: .infer mortal from human.
3: 
4: human(socrates).
5: 
6: mortal(X) :- human(X).
7: 
8: ?- mortal(socrates).
  • Lines 1-2 define two relations, an extensional relation named human and an intensional relation named mortal. Each relation schema comprises a single, unlabeled, string attribute.
  • Line 4 makes the assertion that Socrates is human.
  • Line 6 is the rule that any human is also therefore mortal.
  • Line 8 is a query that effectively asks is there a fact in the mortal relation where the attribute is “socrates”?.

The outcome of this will be of the form:

+------------+
| _: boolean |
+============+
| true       |
+------------+

 


1

Syntax diagrams are generated by bottlecaps.de.