2017-08-10 19:04:45 +00:00
|
|
|
#lang syndicate/core
|
2015-11-03 02:40:12 +00:00
|
|
|
;; Simple mutable box and count-to-infinity box client.
|
|
|
|
|
|
|
|
(struct set-box (new-value) #:transparent)
|
|
|
|
(struct box-state (value) #:transparent)
|
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(actor (lambda (e current-value)
|
2016-03-16 17:13:04 +00:00
|
|
|
(match-event e
|
2015-11-03 02:40:12 +00:00
|
|
|
[(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))
|
2016-03-16 17:13:04 +00:00
|
|
|
(assert (box-state new-value))))]))
|
2015-11-03 02:40:12 +00:00
|
|
|
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
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(actor (lambda (e s)
|
2016-03-16 17:13:04 +00:00
|
|
|
(match-event e
|
2015-11-03 02:40:12 +00:00
|
|
|
[(patch added removed)
|
2016-02-05 18:20:13 +00:00
|
|
|
(transition s (for-trie/list ([(box-state $v) added])
|
2015-12-03 20:53:53 +00:00
|
|
|
(log-info "client: learned that box's value is now ~v" v)
|
2016-03-16 17:13:04 +00:00
|
|
|
(message (set-box (+ v 1)))))]))
|
2015-11-03 02:40:12 +00:00
|
|
|
(void)
|
2015-12-03 20:53:07 +00:00
|
|
|
(patch-seq (sub (box-state ?))))
|