2016-04-01 23:53:46 +00:00
|
|
|
#lang syndicate
|
2016-01-16 19:32:04 +00:00
|
|
|
;; Hello-worldish "bank account" example.
|
|
|
|
|
|
|
|
(struct account (balance) #:prefab)
|
2016-01-18 22:38:58 +00:00
|
|
|
(struct deposit (amount) #:prefab)
|
2016-01-16 19:32:04 +00:00
|
|
|
|
2016-01-18 22:38:58 +00:00
|
|
|
(define (manager e balance)
|
2016-03-01 21:45:29 +00:00
|
|
|
(match-event e
|
2016-01-18 22:38:58 +00:00
|
|
|
[(message (deposit amount))
|
|
|
|
(transition (+ balance amount) (patch-seq (retract (account balance))
|
2016-03-01 21:45:29 +00:00
|
|
|
(assert (account (+ balance amount)))))]))
|
2016-01-16 19:32:04 +00:00
|
|
|
|
2016-01-18 22:38:58 +00:00
|
|
|
(define (observer e _)
|
2016-02-29 18:44:45 +00:00
|
|
|
(when (patch? e) (for [(balance (project-assertions (patch-added e) (account (?!))))]
|
2016-03-01 21:45:29 +00:00
|
|
|
(printf "Balance changed to ~a\n" balance))))
|
2016-01-16 19:32:04 +00:00
|
|
|
|
2016-01-18 22:38:58 +00:00
|
|
|
(define (updater e _)
|
2016-03-01 21:48:28 +00:00
|
|
|
(when (patch/added? e)
|
2016-03-01 21:45:29 +00:00
|
|
|
(quit (list (message (deposit +100))
|
|
|
|
(message (deposit -30))))))
|
2016-01-18 22:38:58 +00:00
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(actor manager 0 (patch-seq (assert (observe (deposit ?))) (assert (account 0))))
|
|
|
|
(actor observer (void) (assert (observe (account ?))))
|
|
|
|
(actor updater (void) (assert (observe (observe (deposit ?)))))
|