Restore syndicate-examples package; port box-and-client.rkt

This commit is contained in:
Tony Garnock-Jones 2021-06-03 22:36:29 +02:00
parent 7b600c51df
commit d648af920a
7 changed files with 63 additions and 45 deletions

View File

@ -1,8 +1,5 @@
# PACKAGES=syndicate syndicate-examples
# COLLECTS=syndicate syndicate-examples
PACKAGES=syndicate
COLLECTS=syndicate
PACKAGES=syndicate syndicate-examples
COLLECTS=syndicate syndicate-examples
all: setup

View File

@ -1,21 +0,0 @@
#lang syndicate
;; Simple mutable box and count-to-infinity box client.
(message-struct set-box (new-value))
(assertion-struct box-state (value))
(spawn (field [current-value 0])
(assert (box-state (current-value)))
(stop-when-true (= (current-value) 10)
(log-info "box: terminating"))
(on (message (set-box $new-value))
(log-info "box: taking on new-value ~v" new-value)
(current-value new-value)))
(spawn (stop-when (retracted (observe (set-box _)))
(log-info "client: box has gone"))
(on (asserted (box-state $v))
(log-info "client: learned that box's value is now ~v" v)
(send! (set-box (+ v 1))))
(on (retracted (box-state _))
(log-info "client: box state disappeared")))

View File

@ -1,18 +0,0 @@
#lang setup/infotab
(define collection "syndicate-examples")
(define deps '("base"
"syndicate"
"bitsyntax"
"packet-socket"
"compatibility-lib"
"data-lib"
"gui-lib"
"htdp-lib"
"images-lib"
"net-lib"
"pict-lib"
"plot-lib"
"srfi-lite-lib"))
(define build-deps '("rackunit-lib"))

View File

@ -0,0 +1,26 @@
#lang syndicate
;; Simple mutable box and count-to-infinity box client.
(struct set-box (new-value) #:prefab)
(struct box-state (value) #:prefab)
(actor-system/dataspace (ds)
(spawn #:name 'box
(define-field current-value 0)
(at ds
(assert (box-state (current-value)))
(when (message (set-box $new-value))
(log-info "box: taking on new-value ~v" new-value)
(current-value new-value)))
(stop-when-true (= (current-value) 10)
(log-info "box: terminating")))
(spawn #:name 'client
(at ds
(stop-when (retracted (Observe (:pattern (set-box ,_)) _))
(log-info "client: box has gone"))
(when (asserted (box-state $v))
(log-info "client: learned that box's value is now ~v" v)
(send! ds (set-box (+ v 1))))
(when (retracted (box-state _))
(log-info "client: box state disappeared")))))

View File

@ -0,0 +1,24 @@
#lang setup/infotab
(define collection "syndicate-examples")
(define deps '(
"base"
"syndicate"
;; "bitsyntax"
;; "packet-socket"
;; "compatibility-lib"
;; "data-lib"
;; "gui-lib"
;; "htdp-lib"
;; "images-lib"
;; "net-lib"
;; "pict-lib"
;; "plot-lib"
;; "srfi-lite-lib"
))
;; (define build-deps '("rackunit-lib"))

10
syndicate/lang.rkt Normal file
View File

@ -0,0 +1,10 @@
#lang racket/base
(provide (all-from-out racket/base)
(all-from-out racket/match)
(all-from-out "main.rkt")
(all-from-out "dataspace.rkt"))
(require racket/match)
(require "main.rkt")
(require "dataspace.rkt")

View File

@ -11,4 +11,4 @@
(require preserves)
(require (only-in "pattern.rkt" :pattern :template))
;; (module reader syntax/module-reader syndicate/lang)
(module reader syntax/module-reader syndicate/lang)