6 Pretty-Printing
This library provides facilities for pretty-printing Datalog source. It can be required via:
This library depends on the pprint PLaneT package, which can be required via:
(require (planet dherman/pprint:4))
See the documentation for pprint for information on how to use it.
| (format-datum d) → doc? |
| d : datum/c |
Examples: |
| > (pretty-print (format-datum 'sym)) |
sym |
| > (pretty-print (format-datum "str")) |
"str" |
| (format-variable v) → doc? |
| v : variable? |
Formats a variable.
Example: |
| > (pretty-print (format-variable (make-variable #f 'Ancestor))) |
Ancestor |
| (format-constant c) → doc? |
| c : constant? |
Formats a constant.
Examples: |
| > (pretty-print (format-constant (make-constant #f 'joseph))) |
joseph |
| > (pretty-print (format-constant (make-constant #f "whom"))) |
"whom" |
| (format-term t) → doc? |
| t : term/c |
Examples: |
| > (pretty-print (format-term (make-variable #f 'Ancestor))) |
Ancestor |
| > (pretty-print (format-term (make-constant #f 'joseph))) |
joseph |
| > (pretty-print (format-term (make-constant #f "whom"))) |
"whom" |
| (format-literal l) → doc? |
| l : literal? |
Formats a literal.
Examples: |
| > (pretty-print (format-literal (make-literal #f 'true (list)))) |
true |
| > (pretty-print | | (format-literal | | (make-literal #f 'ancestor | | (list (make-variable #f 'A) (make-constant #f 'jay))))) |
|
ancestor(A, jay) |
| > (pretty-print | | (format-literal | | (make-literal #f '= | | (list (make-constant #f 'joseph) (make-constant #f 'jay))))) |
|
joseph = jay |
| (format-literals ls) → doc? |
| ls : (listof literal?) |
Formats a list of literals as assertions for formatting prove results.
Example: |
| > (pretty-print | | (format-literals | | (list | | (make-literal #f 'true (list)) | | (make-literal #f 'ancestor | | (list (make-constant #f 'joseph) (make-constant #f 'jay))) | | (make-literal #f '= | | (list (make-constant #f 'joseph) (make-constant #f 'jay)))))) |
|
true. | ancestor(joseph, jay). | joseph = jay. | |
|
| (format-clause c) → doc? |
| c : clause? |
Formats a clause.
Examples: |
| > (pretty-print | | (format-clause | | (make-clause | | #f (make-literal #f 'ancestor | | (list (make-constant #f 'joseph) | | (make-constant #f 'jay))) | | (list)))) |
|
ancestor(joseph, jay) |
| > (pretty-print | | (format-clause | | (make-clause | | #f (make-literal | | #f 'ancestor | | (list (make-constant #f 'A) (make-constant #f 'B))) | | (list (make-literal | | #f 'parent | | (list (make-constant #f 'A) (make-constant #f 'B))))))) |
|
ancestor(A, B) :- parent(A, B) |
| > (pretty-print | | (format-clause | | (make-clause | | #f (make-literal | | #f 'ancestor | | (list (make-constant #f 'A) (make-constant #f 'B))) | | (list (make-literal | | #f 'parent | | (list (make-constant #f 'A) (make-constant #f 'C))) | | (make-literal | | #f 'ancestor | | (list (make-constant #f 'C) (make-constant #f 'B))))))) |
|
ancestor(A, B) :- parent(A, C), ancestor(C, B) |
| (format-assertion a) → doc? |
| a : assertion? |
Formats a assertion.
Example: |
| > (pretty-print | | (format-assertion | | (make-assertion | | #f (make-clause | | #f (make-literal #f 'ancestor | | (list (make-constant #f 'joseph) | | (make-constant #f 'jay))) | | (list))))) |
|
ancestor(joseph, jay). |
| (format-retraction r) → doc? |
| r : retraction? |
Formats a retraction.
Example: |
| > (pretty-print | | (format-retraction | | (make-retraction | | #f (make-clause | | #f (make-literal #f 'ancestor | | (list (make-constant #f 'joseph) | | (make-constant #f 'jay))) | | (list))))) |
|
ancestor(joseph, jay)~ |
| (format-query q) → doc? |
| q : query? |
Formats a query.
Example: |
| > (pretty-print | | (format-query | | (make-query | | #f (make-literal #f 'ancestor | | (list (make-constant #f 'joseph) | | (make-constant #f 'jay)))))) |
|
ancestor(joseph, jay)? |
| (format-statement s) → doc? |
| s : statement/c |
Example: |
| > (pretty-print | | (format-statement | | (make-query | | #f (make-literal #f 'ancestor | | (list (make-constant #f 'joseph) | | (make-constant #f 'jay)))))) |
|
ancestor(joseph, jay)? |
| (format-program p) → doc? |
| p : program/c |
Example: |
| > (pretty-print | | (format-program | | (list | | (make-assertion | | #f (make-clause | | #f (make-literal #f 'ancestor | | (list (make-constant #f 'joseph) | | (make-constant #f 'jay))) | | (list))) | | (make-query | | #f (make-literal #f 'ancestor | | (list (make-constant #f 'joseph) | | (make-constant #f 'jay))))))) |
|
ancestor(joseph, jay). | ancestor(joseph, jay)? |
|