Add project-assertions convenience routine.
This commit is contained in:
parent
aa9677dbe1
commit
1d28908600
4
FAQ.md
4
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.
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
matcher-project
|
||||
matcher-project/set
|
||||
matcher-project/set/single
|
||||
project-assertions
|
||||
|
||||
event?
|
||||
action?
|
||||
|
|
|
@ -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]))
|
||||
|
|
|
@ -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]))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]))
|
||||
|
|
|
@ -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]))
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue