syndicate-2017/prospect/examples/box-and-client.rkt

27 lines
922 B
Racket
Raw Normal View History

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))
(transition new-value (patch-seq (retract (box-state current-value))
(assert (box-state new-value))))]
[_ #f]))
0
(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 (?!)))))]
(message (set-box (+ v 1)))))]
[_ #f]))
(void)
(patch-seq (sub (box-state ?))))