From ca0de7d52f9b7d0fbb30d69100f630095e5941ea Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 1 Oct 2017 15:27:58 +0100 Subject: [PATCH] running-total.rkt --- racket/syndicate/examples/actor/running-total.rkt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 racket/syndicate/examples/actor/running-total.rkt diff --git a/racket/syndicate/examples/actor/running-total.rkt b/racket/syndicate/examples/actor/running-total.rkt new file mode 100644 index 0000000..2c5e4a1 --- /dev/null +++ b/racket/syndicate/examples/actor/running-total.rkt @@ -0,0 +1,15 @@ +#lang syndicate +;; Terminal I/O demo program. + +(require (only-in racket/port read-bytes-line-evt)) + +(define e (read-bytes-line-evt (current-input-port) 'any)) + +(spawn (field [total 0]) + (begin/dataflow (printf "The total is ~a.\n" (total))) + (on-stop (printf "Goodbye!\n")) + (on (message (inbound (external-event e (list $input)))) + (cond + [(eof-object? input) (stop-current-facet)] + [(string->number (bytes->string/utf-8 input)) => (lambda (n) (total (+ (total) n)))] + [else (void)])))