2016-04-01 23:53:46 +00:00
|
|
|
#lang syndicate
|
2016-01-16 19:32:04 +00:00
|
|
|
;; Hello-worldish "bank account" example.
|
|
|
|
|
2016-04-01 23:53:46 +00:00
|
|
|
(require syndicate/actor)
|
2016-01-16 19:32:04 +00:00
|
|
|
|
|
|
|
(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-07-09 20:18:30 +00:00
|
|
|
(actor (react (field [balance 0])
|
|
|
|
(assert (account (balance)))
|
|
|
|
(on (message (deposit $amount))
|
|
|
|
(balance (+ (balance) amount)))))
|
2016-01-16 19:32:04 +00:00
|
|
|
|
2016-07-09 20:18:30 +00:00
|
|
|
(actor (react (on (asserted (account $balance))
|
|
|
|
(printf "Balance changed to ~a\n" balance))))
|
2016-01-16 19:32:04 +00:00
|
|
|
|
2016-02-05 23:03:40 +00:00
|
|
|
(actor (until (asserted (observe (deposit _))))
|
|
|
|
(send! (deposit +100))
|
|
|
|
(send! (deposit -30)))
|