3 Abstract Syntax
This library provides the structures that represent Datalog syntax. It can be required via:
Equivalent to
(datum-equal? d1 d2) → boolean? |
d1 : datum/c |
d2 : datum/c |
Examples: |
> (datum-equal? 'sym1 'sym2) |
#f |
> (datum-equal? 'sym1 'sym1) |
#t |
> (datum-equal? "str1" "str2") |
#f |
> (datum-equal? "str1" "str1") |
#t |
(struct | | variable (srcloc sym) | | | #:extra-constructor-name make-variable) |
|
srcloc : srcloc/c |
sym : symbol? |
A logic variable in Datalog.
(This structure does not enforce the requirements for what characters variables can contain, so if you print one out,
it might not be parseable, but it will be executeable.)
(variable-equal? v1 v2) → boolean? |
v1 : variable? |
v2 : variable? |
Equivalent to
(equal? v1 v2) modulo source location.
Examples: |
> (variable-equal? (make-variable #f 'sym) | (make-variable #'sym 'sym)) |
|
#t |
> (variable-equal? (make-variable #f 'sym1) | (make-variable #f 'sym2)) |
|
#f |
(struct | | constant (srcloc datum) | | | #:extra-constructor-name make-constant) |
|
srcloc : srcloc/c |
datum : datum/c |
A constant in Datalog.
(This structure does not enforce the requirements for what characters constants can contain, so if you print one out,
it might not be parseable, but it will be executeable.)
(constant-equal? c1 c2) → boolean? |
c1 : constant? |
c2 : constant? |
Equivalent to
(equal? c1 c2) modulo source location.
Examples: |
> (constant-equal? (make-constant #f 'sym) | (make-constant #'sym 'sym)) |
|
#t |
> (constant-equal? (make-constant #f 'sym) | (make-constant #f "str")) |
|
#f |
Contract for
terms. Equivalent to
(or/c variable? constant?).
(term-equal? t1 t2) → boolean? |
t1 : term/c |
t2 : term/c |
Equivalent to
(equal? t1 t2) modulo source location.
Examples: |
> (term-equal? (make-constant #f 'sym) (make-constant #'sym 'sym)) |
#t |
> (term-equal? (make-constant #f 'sym) (make-constant #f "str")) |
#f |
(struct | | literal (srcloc predicate terms) | | | #:extra-constructor-name make-literal) |
|
srcloc : srcloc/c |
predicate : datum/c |
terms : (listof term/c) |
A literal in Datalog.
(literal-equal? l1 l2) → boolean? |
l1 : literal? |
l2 : literal? |
Equivalent to
(equal? l1 l2) modulo source location.
Examples: |
> (literal-equal? (make-literal #f 'ancestor (list)) | (make-literal #'ancestor 'ancestor (list))) |
|
#t |
> (literal-equal? (make-literal #f 'ancestor (list)) | (make-literal #f 'parent (list))) |
|
#f |
> (literal-equal? (make-literal #f 'ancestor (list)) | (make-literal #f 'ancestor | (list (make-constant #f 'jack)))) |
|
#f |
(struct | | clause (srcloc head body) | | | #:extra-constructor-name make-clause) |
|
srcloc : srcloc/c |
head : literal? |
body : (listof literal?) |
A Datalog clause.
(clause-equal? c1 c2) → boolean? |
c1 : clause? |
c2 : clause? |
Equivalent to
(equal? c1 c2) modulo source location.
Examples: |
> (clause-equal? | (make-clause #f (make-literal #f 'ancestor (list)) (list)) | (make-clause #'clause | (make-literal #f 'ancestor (list)) (list))) |
|
#t |
> (clause-equal? | (make-clause #f (make-literal #f 'ancestor (list)) (list)) | (make-clause #f (make-literal #f 'parent (list)) (list))) |
|
#f |
(struct | | assertion (srcloc clause) | | | #:extra-constructor-name make-assertion) |
|
srcloc : srcloc/c |
clause : clause? |
A Datalog assertion.
(struct | | retraction (srcloc clause) | | | #:extra-constructor-name make-retraction) |
|
srcloc : srcloc/c |
clause : clause? |
A Datalog retraction.
(struct | | query (srcloc clause) | | | #:extra-constructor-name make-query) |
|
srcloc : srcloc/c |
clause : clause? |
A Datalog query.
Contract for
statements.
Equivalent to
(or/c assertion? retraction? query?).
Contract for
programs.
Equivalent to
(listof statement/c).