Use capitalized letters for variables in paren version
This commit is contained in:
parent
b126303628
commit
07142e2305
|
@ -136,9 +136,7 @@ The Datalog REPL accepts new statements that are executed as if they were in the
|
|||
|
||||
The semantics of this language is the same as the normal Datalog language, except it uses a @secref["parenstx"].
|
||||
|
||||
Literals are represented as S-expressions with identifiers for constant symbols, strings for constant strings, and @racket[,id] for variable symbols.
|
||||
|
||||
@racket[unquote], top-level identifiers, and strings are not otherwise allowed in the program.
|
||||
Literals are represented as S-expressions with non-capitalized identifiers for constant symbols, strings for constant strings, and capitalized identifiers for variable symbols. Top-level identifiers and strings are not otherwise allowed in the program.
|
||||
|
||||
The following is a program:
|
||||
@racketmod[datalog/sexp
|
||||
|
@ -147,12 +145,12 @@ The following is a program:
|
|||
(! (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 X Y)
|
||||
(edge X Y)))
|
||||
(! (:- (path X Y)
|
||||
(edge X Z)
|
||||
(path Z Y)))
|
||||
(? (path X Y))]
|
||||
|
||||
The Parenthetical Datalog REPL accepts new statements that are executed as if they were in the original program text.
|
||||
|
||||
|
@ -168,8 +166,6 @@ The Parenthetical Datalog REPL accepts new statements that are executed as if th
|
|||
|
||||
@defform[(= term term)]{ An equality literal. }
|
||||
|
||||
@defform[(unquote symbol)]{ A variable symbol. }
|
||||
|
||||
@include-section["racket.scrbl"]
|
||||
|
||||
@section{Acknowledgments}
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
(define-syntax-parameter top
|
||||
(λ (stx) (raise-syntax-error '#%top "undefined identifier" stx)))
|
||||
(define-syntax-parameter unquote
|
||||
(λ (stx) (raise-syntax-error 'unquote "only allowed inside literals" stx)))
|
||||
(define-syntax-parameter datum
|
||||
(λ (stx) (raise-syntax-error '#%datum "only allowed inside literals" stx)))
|
||||
|
||||
|
@ -18,15 +16,11 @@
|
|||
(syntax-parse
|
||||
stx
|
||||
[(_ . sym:id)
|
||||
(if (char-upper-case? (string-ref (symbol->string (syntax->datum #'sym)) 0))
|
||||
(quasisyntax/loc stx
|
||||
(constant #'#,stx 'sym))]))
|
||||
|
||||
(define-syntax (literal-unquote stx)
|
||||
(syntax-parse
|
||||
stx
|
||||
[(_ sym:id)
|
||||
(variable #'#,stx 'sym))
|
||||
(quasisyntax/loc stx
|
||||
(variable #'#,stx 'sym))]))
|
||||
(constant #'#,stx 'sym)))]))
|
||||
|
||||
(define-syntax (literal-datum stx)
|
||||
(syntax-parse
|
||||
|
@ -45,8 +39,7 @@
|
|||
(quasisyntax/loc stx
|
||||
(literal #'#,stx 'sym
|
||||
(syntax-parameterize ([top (make-rename-transformer #'literal-top)]
|
||||
[datum (make-rename-transformer #'literal-datum)]
|
||||
[unquote (make-rename-transformer #'literal-unquote)])
|
||||
[datum (make-rename-transformer #'literal-datum)])
|
||||
(list e ...))))]))
|
||||
|
||||
(define-syntax (->simple-clause stx)
|
||||
|
@ -84,5 +77,4 @@
|
|||
#%top-interaction
|
||||
#%module-begin
|
||||
! ~ ?
|
||||
:- =
|
||||
unquote)
|
||||
:- =)
|
|
@ -1,12 +1,12 @@
|
|||
#lang datalog/sexp
|
||||
; Equality test
|
||||
(! (:- (ancestor ,A ,B)
|
||||
(parent ,A ,B)))
|
||||
(! (:- (ancestor ,A ,B)
|
||||
(parent ,A ,C)
|
||||
(! (:- (ancestor A B)
|
||||
(parent A B)))
|
||||
(! (:- (ancestor A B)
|
||||
(parent A C)
|
||||
(= D C) ; Unification required
|
||||
(ancestor ,D ,B)))
|
||||
(ancestor D B)))
|
||||
(! (parent john douglas))
|
||||
(! (parent bob john))
|
||||
(! (parent ebbon bob))
|
||||
(? (ancestor ,A ,B))
|
||||
(? (ancestor A B))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
ancestor(ebbon, douglas).
|
||||
ancestor(ebbon, john).
|
||||
ancestor(bob, douglas).
|
||||
ancestor(ebbon, bob).
|
||||
ancestor(bob, john).
|
||||
ancestor(john, douglas).
|
||||
ancestor(bob, douglas).
|
||||
ancestor(ebbon, john).
|
||||
ancestor(ebbon, douglas).
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
(! (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 ,X ,Z)
|
||||
(edge ,Z ,Y)))
|
||||
(? (path ,X ,Y))
|
||||
(! (:- (path X Y)
|
||||
(edge X Y)))
|
||||
(! (:- (path X Y)
|
||||
(edge X Z)
|
||||
(path Z Y)))
|
||||
(! (:- (path X Y)
|
||||
(path X Z)
|
||||
(edge Z Y)))
|
||||
(? (path X Y))
|
|
@ -2,12 +2,12 @@
|
|||
; Laps Test
|
||||
(! (contains ca store rams_couch rams))
|
||||
(! (contains rams fetch rams_couch will))
|
||||
(! (:- (contains ca fetch ,Name ,Watcher)
|
||||
(contains ca store ,Name ,Owner)
|
||||
(contains ,Owner fetch ,Name ,Watcher)))
|
||||
(! (:- (contains ca fetch Name Watcher)
|
||||
(contains ca store Name Owner)
|
||||
(contains Owner fetch Name Watcher)))
|
||||
(! (trusted ca))
|
||||
(! (:- (permit ,User ,Priv ,Name)
|
||||
(contains ,Auth ,Priv ,Name ,User)
|
||||
(trusted ,Auth)))
|
||||
(? (permit ,User ,Priv ,Name))
|
||||
(! (:- (permit User Priv Name)
|
||||
(contains Auth Priv Name User)
|
||||
(trusted Auth)))
|
||||
(? (permit User Priv Name))
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
(! (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 X Y)
|
||||
(edge X Y)))
|
||||
(! (:- (path X Y)
|
||||
(edge X Z)
|
||||
(path Z Y)))
|
||||
(? (path X Y))
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#lang datalog/sexp
|
||||
; p q test from Chen & Warren
|
||||
(! (:- (q ,X)
|
||||
(p ,X)))
|
||||
(! (:- (q X)
|
||||
(p X)))
|
||||
(! (q a))
|
||||
(! (:- (p ,X)
|
||||
(q ,X)))
|
||||
(? (q ,X))
|
||||
(! (:- (p X)
|
||||
(q X)))
|
||||
(? (q X))
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
(! (edge b c))
|
||||
(! (edge c d))
|
||||
(! (edge d a))
|
||||
(! (:- (path ,X ,Y)
|
||||
(edge ,X ,Y)))
|
||||
(! (:- (path ,X ,Y)
|
||||
(path ,X ,Z)
|
||||
(edge ,Z ,Y)))
|
||||
(? (path ,X ,Y))
|
||||
(! (:- (path X Y)
|
||||
(edge X Y)))
|
||||
(! (:- (path X Y)
|
||||
(path X Z)
|
||||
(edge Z Y)))
|
||||
(? (path X Y))
|
|
@ -1,7 +1,7 @@
|
|||
#lang datalog/sexp
|
||||
(! (tpme tpme1))
|
||||
(! (ms m1 "TPME" tpme1 ek tp))
|
||||
(! (:- (says ,TPME ,M)
|
||||
(tpme ,TPME)
|
||||
(ms ,M "TPME" ,TPME ,A ,B)))
|
||||
(? (says ,A ,B))
|
||||
(! (:- (says TPME M)
|
||||
(tpme TPME)
|
||||
(ms M "TPME" TPME A B)))
|
||||
(? (says A B))
|
||||
|
|
|
@ -6,23 +6,23 @@
|
|||
|
||||
(! (parent bob john))
|
||||
(! (parent ebbon bob))
|
||||
(? (parent ,A ,B))
|
||||
(? (parent A B))
|
||||
|
||||
(? (parent john ,B))
|
||||
(? (parent john B))
|
||||
|
||||
(? (parent ,A ,A))
|
||||
(? (parent A A))
|
||||
|
||||
(! (:- (ancestor ,A ,B)
|
||||
(parent ,A ,B)))
|
||||
(! (:- (ancestor ,A ,B)
|
||||
(parent ,A ,C)
|
||||
(ancestor ,C ,B)))
|
||||
(? (ancestor ,A ,B))
|
||||
(! (:- (ancestor A B)
|
||||
(parent A B)))
|
||||
(! (:- (ancestor A B)
|
||||
(parent A C)
|
||||
(ancestor C B)))
|
||||
(? (ancestor A B))
|
||||
|
||||
(? (ancestor ,X john))
|
||||
(? (ancestor X john))
|
||||
|
||||
(~ (parent bob john))
|
||||
|
||||
(? (parent ,A ,B))
|
||||
(? (parent A B))
|
||||
|
||||
(? (ancestor ,A ,B))
|
||||
(? (ancestor A B))
|
||||
|
|
Loading…
Reference in New Issue
Block a user