Use capitalized letters for variables in paren version

This commit is contained in:
Jay McCarthy 2010-06-26 13:17:10 -06:00
parent b126303628
commit 07142e2305
11 changed files with 72 additions and 84 deletions

View File

@ -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"]. 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. 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.
@racket[unquote], top-level identifiers, and strings are not otherwise allowed in the program.
The following is a program: The following is a program:
@racketmod[datalog/sexp @racketmod[datalog/sexp
@ -147,12 +145,12 @@ The following is a program:
(! (edge b c)) (! (edge b c))
(! (edge c d)) (! (edge c d))
(! (edge d a)) (! (edge d a))
(! (:- (path ,X ,Y) (! (:- (path X Y)
(edge ,X ,Y))) (edge X Y)))
(! (:- (path ,X ,Y) (! (:- (path X Y)
(edge ,X ,Z) (edge X Z)
(path ,Z ,Y))) (path Z Y)))
(? (path ,X ,Y))] (? (path X Y))]
The Parenthetical Datalog REPL accepts new statements that are executed as if they were in the original program text. 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[(= term term)]{ An equality literal. }
@defform[(unquote symbol)]{ A variable symbol. }
@include-section["racket.scrbl"] @include-section["racket.scrbl"]
@section{Acknowledgments} @section{Acknowledgments}

View File

@ -9,8 +9,6 @@
(define-syntax-parameter top (define-syntax-parameter top
(λ (stx) (raise-syntax-error '#%top "undefined identifier" stx))) (λ (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 (define-syntax-parameter datum
(λ (stx) (raise-syntax-error '#%datum "only allowed inside literals" stx))) (λ (stx) (raise-syntax-error '#%datum "only allowed inside literals" stx)))
@ -18,15 +16,11 @@
(syntax-parse (syntax-parse
stx stx
[(_ . sym:id) [(_ . sym:id)
(quasisyntax/loc stx (if (char-upper-case? (string-ref (symbol->string (syntax->datum #'sym)) 0))
(constant #'#,stx 'sym))])) (quasisyntax/loc stx
(variable #'#,stx 'sym))
(define-syntax (literal-unquote stx) (quasisyntax/loc stx
(syntax-parse (constant #'#,stx 'sym)))]))
stx
[(_ sym:id)
(quasisyntax/loc stx
(variable #'#,stx 'sym))]))
(define-syntax (literal-datum stx) (define-syntax (literal-datum stx)
(syntax-parse (syntax-parse
@ -45,8 +39,7 @@
(quasisyntax/loc stx (quasisyntax/loc stx
(literal #'#,stx 'sym (literal #'#,stx 'sym
(syntax-parameterize ([top (make-rename-transformer #'literal-top)] (syntax-parameterize ([top (make-rename-transformer #'literal-top)]
[datum (make-rename-transformer #'literal-datum)] [datum (make-rename-transformer #'literal-datum)])
[unquote (make-rename-transformer #'literal-unquote)])
(list e ...))))])) (list e ...))))]))
(define-syntax (->simple-clause stx) (define-syntax (->simple-clause stx)
@ -84,5 +77,4 @@
#%top-interaction #%top-interaction
#%module-begin #%module-begin
! ~ ? ! ~ ?
:- = :- =)
unquote)

View File

@ -1,12 +1,12 @@
#lang datalog/sexp #lang datalog/sexp
; Equality test ; Equality test
(! (:- (ancestor ,A ,B) (! (:- (ancestor A B)
(parent ,A ,B))) (parent A B)))
(! (:- (ancestor ,A ,B) (! (:- (ancestor A B)
(parent ,A ,C) (parent A C)
(= D C) ; Unification required (= D C) ; Unification required
(ancestor ,D ,B))) (ancestor D B)))
(! (parent john douglas)) (! (parent john douglas))
(! (parent bob john)) (! (parent bob john))
(! (parent ebbon bob)) (! (parent ebbon bob))
(? (ancestor ,A ,B)) (? (ancestor A B))

View File

@ -1,6 +1,6 @@
ancestor(ebbon, douglas).
ancestor(ebbon, john).
ancestor(bob, douglas).
ancestor(ebbon, bob). ancestor(ebbon, bob).
ancestor(bob, john). ancestor(bob, john).
ancestor(john, douglas). ancestor(john, douglas).
ancestor(bob, douglas).
ancestor(ebbon, john).
ancestor(ebbon, douglas).

View File

@ -4,12 +4,12 @@
(! (edge b c)) (! (edge b c))
(! (edge c d)) (! (edge c d))
(! (edge d a)) (! (edge d a))
(! (:- (path ,X ,Y) (! (:- (path X Y)
(edge ,X ,Y))) (edge X Y)))
(! (:- (path ,X ,Y) (! (:- (path X Y)
(edge ,X ,Z) (edge X Z)
(path ,Z ,Y))) (path Z Y)))
(! (:- (path ,X ,Y) (! (:- (path X Y)
(path ,X ,Z) (path X Z)
(edge ,Z ,Y))) (edge Z Y)))
(? (path ,X ,Y)) (? (path X Y))

View File

@ -2,12 +2,12 @@
; Laps Test ; Laps Test
(! (contains ca store rams_couch rams)) (! (contains ca store rams_couch rams))
(! (contains rams fetch rams_couch will)) (! (contains rams fetch rams_couch will))
(! (:- (contains ca fetch ,Name ,Watcher) (! (:- (contains ca fetch Name Watcher)
(contains ca store ,Name ,Owner) (contains ca store Name Owner)
(contains ,Owner fetch ,Name ,Watcher))) (contains Owner fetch Name Watcher)))
(! (trusted ca)) (! (trusted ca))
(! (:- (permit ,User ,Priv ,Name) (! (:- (permit User Priv Name)
(contains ,Auth ,Priv ,Name ,User) (contains Auth Priv Name User)
(trusted ,Auth))) (trusted Auth)))
(? (permit ,User ,Priv ,Name)) (? (permit User Priv Name))

View File

@ -4,9 +4,9 @@
(! (edge b c)) (! (edge b c))
(! (edge c d)) (! (edge c d))
(! (edge d a)) (! (edge d a))
(! (:- (path ,X ,Y) (! (:- (path X Y)
(edge ,X ,Y))) (edge X Y)))
(! (:- (path ,X ,Y) (! (:- (path X Y)
(edge ,X ,Z) (edge X Z)
(path ,Z ,Y))) (path Z Y)))
(? (path ,X ,Y)) (? (path X Y))

View File

@ -1,8 +1,8 @@
#lang datalog/sexp #lang datalog/sexp
; p q test from Chen & Warren ; p q test from Chen & Warren
(! (:- (q ,X) (! (:- (q X)
(p ,X))) (p X)))
(! (q a)) (! (q a))
(! (:- (p ,X) (! (:- (p X)
(q ,X))) (q X)))
(? (q ,X)) (? (q X))

View File

@ -4,9 +4,9 @@
(! (edge b c)) (! (edge b c))
(! (edge c d)) (! (edge c d))
(! (edge d a)) (! (edge d a))
(! (:- (path ,X ,Y) (! (:- (path X Y)
(edge ,X ,Y))) (edge X Y)))
(! (:- (path ,X ,Y) (! (:- (path X Y)
(path ,X ,Z) (path X Z)
(edge ,Z ,Y))) (edge Z Y)))
(? (path ,X ,Y)) (? (path X Y))

View File

@ -1,7 +1,7 @@
#lang datalog/sexp #lang datalog/sexp
(! (tpme tpme1)) (! (tpme tpme1))
(! (ms m1 "TPME" tpme1 ek tp)) (! (ms m1 "TPME" tpme1 ek tp))
(! (:- (says ,TPME ,M) (! (:- (says TPME M)
(tpme ,TPME) (tpme TPME)
(ms ,M "TPME" ,TPME ,A ,B))) (ms M "TPME" TPME A B)))
(? (says ,A ,B)) (? (says A B))

View File

@ -6,23 +6,23 @@
(! (parent bob john)) (! (parent bob john))
(! (parent ebbon bob)) (! (parent ebbon bob))
(? (parent ,A ,B)) (? (parent A B))
(? (parent john ,B)) (? (parent john B))
(? (parent ,A ,A)) (? (parent A A))
(! (:- (ancestor ,A ,B) (! (:- (ancestor A B)
(parent ,A ,B))) (parent A B)))
(! (:- (ancestor ,A ,B) (! (:- (ancestor A B)
(parent ,A ,C) (parent A C)
(ancestor ,C ,B))) (ancestor C B)))
(? (ancestor ,A ,B)) (? (ancestor A B))
(? (ancestor ,X john)) (? (ancestor X john))
(~ (parent bob john)) (~ (parent bob john))
(? (parent ,A ,B)) (? (parent A B))
(? (ancestor ,A ,B)) (? (ancestor A B))