On this page:
current-theory
eval-program
eval-statement
eval-program/ fresh

8 Evaluation

This library provides facilities for evaluating Datalog. It can be required via:

 (require (planet jaymccarthy/datalog:1:3/eval))

current-theory : (parameter/c mutable-theory/c)
The theory used by eval-program and eval-stmt.

(eval-program p)  void
  p : program/c
Evaluates p using (current-theory) as the theory, printing query answers as it goes.

This will raise a syntax error if given an assertion of a clause that is not a safe-clause?.

Examples:

  > (parameterize ([current-theory (make-mutable-theory)])
      (eval-program
       (parse-program
        (open-input-string
         (string-append
          "edge(a, b). edge(b, c). edge(c, d). edge(d, a)."
          "path(X, Y) :- edge(X, Y)."
          "path(X, Y) :- edge(X, Z), path(Z, Y)."
          "path(X, Y)?")))))

  path(a, a).

  path(a, d).

  path(a, c).

  path(a, b).

  path(b, a).

  path(b, d).

  path(b, c).

  path(b, b).

  path(c, a).

  path(c, d).

  path(c, c).

  path(c, b).

  path(d, b).

  path(d, c).

  path(d, d).

  path(d, a).

  

  > (eval-program
     (parse-program
      (open-input-string
       "path(X, Y) :- edge(X, a).")))

  string:1:0: datalog: Unsafe clause in assertion in:

  "path(X, Y) :- edge(X, a)."

(eval-statement s)  (or/c void (listof literal?))
  s : statement/c
Evaluates s using (current-theory) as the theory.

This will raise a syntax error if given an assertion of a clause that is not a safe-clause?.

Examples:

  > (parameterize ([current-theory (make-mutable-theory)])
      (eval-statement
       (parse-statement
        (open-input-string
         "edge(a, b).")))
      (eval-statement
       (parse-statement
        (open-input-string
         "path(X, Y) :- edge(X, Y).")))
      (eval-statement
       (parse-statement
        (open-input-string
         "path(X, Y)?"))))

  `(#s(literal (string 1 0 1 10) path (#s(constant (string 1 5 6 1) a) #s(constant (string 1 8 9 1) b))))

  > (eval-statement
     (parse-statement
      (open-input-string
       "path(X, Y) :- edge(X, a).")))

  string:1:0: datalog: Unsafe clause in assertion in:

  "path(X, Y) :- edge(X, a)."

(eval-program/fresh p)  immutable-theory/c
  p : program/c
Evaluates p in a fresh theory and returns the final theory, printing query answers as it goes.

This will raise a syntax error if given an assertion of a clause that is not a safe-clause?.

Examples:

  > (void
     (eval-program/fresh
      (parse-program
       (open-input-string
        (string-append
         "edge(a, b). edge(b, c). edge(c, d). edge(d, a)."
         "path(X, Y) :- edge(X, Y)."
         "path(X, Y) :- edge(X, Z), path(Z, Y)."
         "path(X, Y)?")))))

  path(a, a).

  path(a, d).

  path(a, c).

  path(a, b).

  path(b, a).

  path(b, d).

  path(b, c).

  path(b, b).

  path(c, a).

  path(c, d).

  path(c, c).

  path(c, b).

  path(d, b).

  path(d, c).

  path(d, d).

  path(d, a).

  

  > (eval-program/fresh
     (parse-program
      (open-input-string
       "path(X, Y) :- edge(X, a).")))

  string:1:0: datalog: Unsafe clause in assertion in:

  "path(X, Y) :- edge(X, a)."