On this page:
srcloc/ c
datum/ c
datum-equal?
variable
variable-equal?
constant
constant-equal?
term/ c
term-equal?
literal
literal-equal?
clause
clause-equal?
assertion
retraction
query
statement/ c
program/ c
Version: 4.1.5.1

3 Abstract Syntax

This library provides the structures that represent Datalog syntax. It can be required via:

 (require (planet jaymccarthy/datalog:1:1/ast))

srcloc/c : contract?

Contract for the third argument to datum->syntax.

Equivalent to

  (or/c syntax?
        false/c
        (list/c any/c
                (or/c exact-positive-integer? #f)
                (or/c exact-nonnegative-integer? #f)
                (or/c exact-nonnegative-integer? #f)
                (or/c exact-positive-integer? #f)))

datum/c : contract?

Contract for datums. Equivalent to (or/c string? symbol?).

(datum-equal? d1 d2)  boolean?
  d1 : datum/c
  d2 : datum/c

Equivalent to (equal? d1 d2).

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))
  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))
  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

term/c : contract?

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))
  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))
  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))
  srcloc : srcloc/c
  clause : clause?

A Datalog assertion.

(struct retraction (srcloc clause))
  srcloc : srcloc/c
  clause : clause?

A Datalog retraction.

(struct query (srcloc clause))
  srcloc : srcloc/c
  clause : clause?

A Datalog query.

statement/c : contract?

Contract for statements. Equivalent to (or/c assertion? retraction? query?).

program/c : contract?

Contract for programs. Equivalent to (listof statement/c).