diff --git a/FAQ.md b/FAQ.md index 2bfa57d..cea22eb 100644 --- a/FAQ.md +++ b/FAQ.md @@ -164,8 +164,8 @@ (compile-projection (?! `(posn ,? ,?)))) ``` with the same example yields `(set (list ('posn 2 3))`. - - `matcher-project/set/single` is like calling `set-first` on the result of - `matcher-project/set` + - `matcher-project/set/single` is like mapping `car` over the result of + `matcher-project/set`. See also `project-assertions`. - `patch-project/set` uses `values` to return the result of matching a projection against both the added and removed bits of a patch. diff --git a/prospect/core.rkt b/prospect/core.rkt index b5f0992..2d0db9d 100644 --- a/prospect/core.rkt +++ b/prospect/core.rkt @@ -29,6 +29,7 @@ matcher-project matcher-project/set matcher-project/set/single + project-assertions event? action? diff --git a/prospect/examples/bank-account.rkt b/prospect/examples/bank-account.rkt index 1afaf56..5ef7de8 100644 --- a/prospect/examples/bank-account.rkt +++ b/prospect/examples/bank-account.rkt @@ -19,7 +19,7 @@ (spawn (lambda (e s) (match e [(patch added removed) - (for [(balance (matcher-project/set/single added (compile-projection (account (?!)))))] + (for [(balance (project-assertions added (account (?!))))] (printf "Balance changed to ~a\n" balance)) #f] [_ #f])) diff --git a/prospect/examples/box-and-client.rkt b/prospect/examples/box-and-client.rkt index b6e6d48..6191053 100644 --- a/prospect/examples/box-and-client.rkt +++ b/prospect/examples/box-and-client.rkt @@ -18,9 +18,7 @@ (spawn (lambda (e s) (match e [(patch added removed) - (transition s (for/list [(v (matcher-project/set/single - added - (compile-projection (box-state (?!)))))] + (transition s (for/list [(v (project-assertions added (box-state (?!))))] (log-info "client: learned that box's value is now ~v" v) (message (set-box (+ v 1)))))] [_ #f])) diff --git a/prospect/examples/chat-simplified-internals.rkt b/prospect/examples/chat-simplified-internals.rkt index 1320030..29e1690 100644 --- a/prospect/examples/chat-simplified-internals.rkt +++ b/prospect/examples/chat-simplified-internals.rkt @@ -73,9 +73,8 @@ (spawn (lambda (e s) (if (patch? e) (transition s - (for/list [(id (matcher-project/set/single - (patch-added e) - (compile-projection (tcp-remote-open (?!)))))] + (for/list [(id (project-assertions (patch-added e) + (tcp-remote-open (?!))))] (spawn-session id))) #f)) (void) diff --git a/prospect/examples/durable-key-value-store.rkt b/prospect/examples/durable-key-value-store.rkt index 938abe5..a412e8d 100644 --- a/prospect/examples/durable-key-value-store.rkt +++ b/prospect/examples/durable-key-value-store.rkt @@ -129,7 +129,7 @@ (spawn (lambda (e s) (match e [(? patch? p) - (define n (matcher-project/set/single (patch-added p) (compile-projection (?!)))) + (define n (project-assertions (patch-added p) (?!))) (for [(b n)] (printf "binding update: ~v\n" b)) #f] [_ #f])) diff --git a/prospect/examples/key-value-store.rkt b/prospect/examples/key-value-store.rkt index 1741eb2..436f1ca 100644 --- a/prospect/examples/key-value-store.rkt +++ b/prospect/examples/key-value-store.rkt @@ -107,7 +107,7 @@ (spawn (lambda (e s) (match e [(? patch? p) - (define n (matcher-project/set/single (patch-added p) (compile-projection (?!)))) + (define n (project-assertions (patch-added p) (?!))) (for [(b n)] (printf "binding update: ~v\n" b)) #f] [_ #f])) diff --git a/prospect/route.rkt b/prospect/route.rkt index b1ec778..fef96de 100644 --- a/prospect/route.rkt +++ b/prospect/route.rkt @@ -50,6 +50,7 @@ matcher-key-set/single matcher-project/set matcher-project/set/single + project-assertions ;; composition of matcher-project/set/single with compile-projection ;; Printing and Serialization pretty-print-matcher @@ -818,6 +819,10 @@ (define-syntax-rule (matcher-project/set/single arg ...) (matcher-key-set/single (matcher-project arg ...))) +;; Ultra-convenience form. +(define (project-assertions m . ps) + (matcher-project/set/single m (compile-projection* ps))) + ;; struct-type -> Symbol ;; Extract just the name of the given struct-type. (define (struct-type-name st)