#lang imperative-syndicate (require/activate imperative-syndicate/distributed) (require/activate imperative-syndicate/drivers/external-event) (require (only-in racket/port read-line-evt)) (assertion-struct Present (name)) (message-struct Says (who what)) (spawn #:name 'main (field [username (symbol->string (strong-gensym 'chatter-))]) (define root-facet (current-facet)) (define url standard-localhost-server/tcp) (during (server-connected url) (on-start (log-info "Connected to server.")) (on-stop (log-info "Disconnected from server.")) (on (asserted (from-server url (Present $who))) (printf "~a arrived.\n" who)) (on (retracted (from-server url (Present $who))) (printf "~a departed.\n" who)) (on (message (from-server url (Says $who $what))) (printf "~a: ~a\n" who what)) (assert (to-server url (Present (username)))) (define stdin-evt (read-line-evt (current-input-port) 'any)) (on (message (inbound (external-event stdin-evt (list $line)))) (match line [(? eof-object?) (stop-facet root-facet)] [(pregexp #px"^/nick (.+)$" (list _ newnick)) (username newnick)] [other (send! (to-server url (Says (username) other)))]))))