2015-11-03 02:40:12 +00:00
|
|
|
#lang prospect
|
|
|
|
;; Simple mutable box and count-to-infinity box client.
|
|
|
|
|
|
|
|
(struct set-box (new-value) #:transparent)
|
|
|
|
(struct box-state (value) #:transparent)
|
|
|
|
|
|
|
|
(spawn (lambda (e current-value)
|
|
|
|
(match e
|
|
|
|
[(message (set-box new-value))
|
2015-12-03 20:53:53 +00:00
|
|
|
(log-info "box: taking on new-value ~v" new-value)
|
2015-11-03 02:40:12 +00:00
|
|
|
(transition new-value (patch-seq (retract (box-state current-value))
|
|
|
|
(assert (box-state new-value))))]
|
|
|
|
[_ #f]))
|
|
|
|
0
|
2015-12-03 20:53:07 +00:00
|
|
|
(patch-seq (sub (set-box ?))
|
|
|
|
(assert (box-state 0))))
|
2015-11-03 02:40:12 +00:00
|
|
|
|
|
|
|
(spawn (lambda (e s)
|
|
|
|
(match e
|
|
|
|
[(patch added removed)
|
|
|
|
(transition s (for/list [(v (matcher-project/set/single
|
|
|
|
added
|
|
|
|
(compile-projection (box-state (?!)))))]
|
2015-12-03 20:53:53 +00:00
|
|
|
(log-info "client: learned that box's value is now ~v" v)
|
2015-11-03 02:40:12 +00:00
|
|
|
(message (set-box (+ v 1)))))]
|
|
|
|
[_ #f]))
|
|
|
|
(void)
|
2015-12-03 20:53:07 +00:00
|
|
|
(patch-seq (sub (box-state ?))))
|