diff --git a/doc/notes-on-hll.md b/doc/notes-on-hll.md index aada9a3..fd15a79 100644 --- a/doc/notes-on-hll.md +++ b/doc/notes-on-hll.md @@ -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)))))) +``` diff --git a/prospect/examples/box-and-client.rkt b/prospect/examples/box-and-client.rkt new file mode 100644 index 0000000..e766c5f --- /dev/null +++ b/prospect/examples/box-and-client.rkt @@ -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 ?)))