syndicate-2017/racket/typed/examples/simple-stop-facet.rkt

39 lines
764 B
Racket
Raw Normal View History

#lang typed/syndicate
2018-07-30 18:01:56 +00:00
;; Expected Output:
;; +42
;; +18
2018-07-31 18:03:15 +00:00
;; +9
2018-07-30 18:01:56 +00:00
;; +88
;; -18
2018-07-31 18:03:15 +00:00
;; -9
2018-07-30 18:01:56 +00:00
(define-type-alias ds-type
(U (Tuple Int)
(Observe (Tuple ★/t))))
(run-ground-dataspace ds-type
2018-07-30 18:01:56 +00:00
(spawn ds-type
(print-role
(start-facet doomed
(assert (tuple 18))
(on (asserted (tuple 42))
(stop doomed
(start-facet the-afterlife
(assert (tuple 88))))))))
(spawn ds-type
(start-facet obs
(assert (tuple 42))
(on (asserted (tuple (bind x Int)))
(printf "+~v\n" x))
(on (retracted (tuple (bind x Int)))
2018-07-31 18:03:15 +00:00
(printf "-~v\n" x))))
;; null-ary stop
(spawn ds-type
(start-facet meep
(assert (tuple 9))
(on (asserted (tuple 88))
(stop meep)))))