Datalog language preview
1. Transitive closure
Souffle directives, a fact, and a recursive rule
horizon-dark
// transitive closure over an edge relation
.decl edge(x: symbol, y: symbol)
.decl path(x: symbol, y: symbol)
.input edge
edge("a", "b").
edge("b", "c").
path(x, y) :- edge(x, y).
path(x, y) :- path(x, z), edge(z, y), !edge(y, x).
.output path atom-one-dark
// transitive closure over an edge relation
.decl edge(x: symbol, y: symbol)
.decl path(x: symbol, y: symbol)
.input edge
edge("a", "b").
edge("b", "c").
path(x, y) :- edge(x, y).
path(x, y) :- path(x, z), edge(z, y), !edge(y, x).
.output path github-dark
// transitive closure over an edge relation
.decl edge(x: symbol, y: symbol)
.decl path(x: symbol, y: symbol)
.input edge
edge("a", "b").
edge("b", "c").
path(x, y) :- edge(x, y).
path(x, y) :- path(x, z), edge(z, y), !edge(y, x).
.output path dracula
// transitive closure over an edge relation
.decl edge(x: symbol, y: symbol)
.decl path(x: symbol, y: symbol)
.input edge
edge("a", "b").
edge("b", "c").
path(x, y) :- edge(x, y).
path(x, y) :- path(x, z), edge(z, y), !edge(y, x).
.output path nord
// transitive closure over an edge relation
.decl edge(x: symbol, y: symbol)
.decl path(x: symbol, y: symbol)
.input edge
edge("a", "b").
edge("b", "c").
path(x, y) :- edge(x, y).
path(x, y) :- path(x, z), edge(z, y), !edge(y, x).
.output path github
// transitive closure over an edge relation
.decl edge(x: symbol, y: symbol)
.decl path(x: symbol, y: symbol)
.input edge
edge("a", "b").
edge("b", "c").
path(x, y) :- edge(x, y).
path(x, y) :- path(x, z), edge(z, y), !edge(y, x).
.output path 2. Type declarations
.type and .functor directives
horizon-dark
.type Name <: symbol
.decl person(name: Name, age: number)
.functor double(x: number): number
person("Ada", 30).
person("Grace", 40). atom-one-dark
.type Name <: symbol
.decl person(name: Name, age: number)
.functor double(x: number): number
person("Ada", 30).
person("Grace", 40). github-dark
.type Name <: symbol
.decl person(name: Name, age: number)
.functor double(x: number): number
person("Ada", 30).
person("Grace", 40). dracula
.type Name <: symbol
.decl person(name: Name, age: number)
.functor double(x: number): number
person("Ada", 30).
person("Grace", 40). nord
.type Name <: symbol
.decl person(name: Name, age: number)
.functor double(x: number): number
person("Ada", 30).
person("Grace", 40). github
.type Name <: symbol
.decl person(name: Name, age: number)
.functor double(x: number): number
person("Ada", 30).
person("Grace", 40). 3. Query with negation
a classic ?- query and negated subgoal
horizon-dark
?- path(X, "c"), !edge(X, "c"). atom-one-dark
?- path(X, "c"), !edge(X, "c"). github-dark
?- path(X, "c"), !edge(X, "c"). dracula
?- path(X, "c"), !edge(X, "c"). nord
?- path(X, "c"), !edge(X, "c"). github
?- path(X, "c"), !edge(X, "c").