4 Racket Interoperability
(require datalog) | package: datalog |
The Datalog database can be directly used by Racket programs through this API.
Examples: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
procedure
(make-theory) → theory/c
procedure
(write-theory t) → void
t : theory/c
procedure
(read-theory) → theory/c
Statements are either assertions, retractions, or queries.
syntax
(! clause)
syntax
(~ clause)
syntax
(:- literal question ...)
syntax
(? question)
Questions are either literals or external queries.
Literals are represented as identifier or (table term ...).
A table is either an identifier or #,expr where expr evaluates to a symbol.
External queries are represented as (ext-table term ... :- term ...), where ext-table is an identifier bound to a procedure or #,expr where expr evaluates to a procedure that when given the first set of terms as arguments returns the second set of terms as values.
A term is either a non-capitalized identifiers for a constant symbol, a Racket expression for a constant datum, or a capitalized identifier for a variable symbol, or #,expr where expr evaluates to a constant datum. Bound identifiers in terms are treated as the datum they are bound to.
External queries fail if any logic variable is not fully resolved to a datum on the Datalog side. In other words, unbound logic variables never flow to Racket.
External queries invalidate Datalog’s guaranteed termination. For example, this program does not terminate:
(datalog (make-theory) (! (:- (loop X) (add1 X :- Z) (loop Z))) (? (loop 1)))