box-and-client example
This commit is contained in:
parent
212900bc1a
commit
7b72d40a70
|
@ -42,3 +42,22 @@ and `I` needs to be clarified, among many other things.
|
|||
|
||||
(define-syntax-rule (forever O ...)
|
||||
(until (rising-edge #f) O ...))
|
||||
|
||||
## Examples
|
||||
|
||||
```racket
|
||||
#lang prospect/actor
|
||||
;; Simple mutable box and count-to-infinity box client.
|
||||
|
||||
(struct set-box (new-value) #:transparent)
|
||||
(struct box-state (value) #:transparent)
|
||||
|
||||
(actor (forever #:collect [(value 0)]
|
||||
(assert (box-state value))
|
||||
(on (message (set-box $new-value))
|
||||
new-value)))
|
||||
|
||||
(actor (forever
|
||||
(on (asserted (box-state $value))
|
||||
(send! (set-box (+ value 1))))))
|
||||
```
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#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
|
||||
(sub (set-box ?))
|
||||
(assert (box-state 0)))
|
||||
|
||||
(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)
|
||||
(sub (box-state ?)))
|
Loading…
Reference in New Issue