From: Tim Vaughan Date: Sat, 1 May 2021 21:11:34 +0000 (+0200) Subject: Updated examples to be compatible with new architecture. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=5d2d076345efb45ced333e832d1cbf766bcd5e8a;p=sam.git Updated examples to be compatible with new architecture. --- diff --git a/chat_client.scm b/chat_client.scm index 947418f..d500579 100644 --- a/chat_client.scm +++ b/chat_client.scm @@ -1,5 +1,4 @@ -(import sam - matchable +(import matchable srfi-13 (chicken process-context)) @@ -69,25 +68,3 @@ (define (main-beh self system) (send-message (make-actor (make-client-beh system)) 'start) 'done) - -(define (print-usage) - (print "Actor-driven chat client.\n") - (print "Usage: chat_client -h") - (print " chat_client [-p port_num] [-n host_name]")) - -(let loop ((args (cdr (argv))) - (host "localhost") - (port 8000)) - (match args - (((or "-h" "--help")) - (print-usage)) - (((or "-p" "--port") pstr rest ...) - (loop rest host (string->number pstr))) - (((or "-n" "--hostname") hstr rest ...) - (loop rest hstr port)) - (() - (boot-sam host port main-beh)) - (else - (print "Unrecognised argument '" (car args) "'.\n") - (print-usage)))) - diff --git a/sam.scm b/sam.scm index 93906b9..1d23712 100644 --- a/sam.scm +++ b/sam.scm @@ -11,6 +11,7 @@ (chicken port) (chicken process-context) (chicken file) + (chicken condition) matchable srfi-18 ; threads srfi-69 ; hash-table @@ -203,7 +204,15 @@ (define (boot-sam) (start-console) (start-network-listener) - (send-message (make-actor main-beh) (make-actor system-beh)) + (let ((system (make-actor system-beh)) + (main #f)) + (condition-case + (begin + (set! main (make-actor main-beh))) + ((exn) + (print "Error starting main actor. Is main-beh defined?") + (exit 1))) + (send-message main system)) (start-scheduler)) (define (print-usage) @@ -222,14 +231,14 @@ (loop rest)) (((or "-n" "--hostname") hstr rest ...) (set! sam-host hstr) - (loop rest) - (((? file-exists? filename) rest ...)) + (loop rest)) + (((? file-exists? filename) rest ...) (print* "Loading " filename "...") (load filename) (print " done.") (loop rest)) (() - (boot-sam host port main-beh)) + (boot-sam)) (else (print "Unrecognised argument '" (car args) "'.\n") (print-usage)))) diff --git a/simple_test.scm b/simple_test.scm index cd6149b..f20d203 100644 --- a/simple_test.scm +++ b/simple_test.scm @@ -1,5 +1,4 @@ -(import sam - matchable +(import matchable (chicken process-context) srfi-18) @@ -7,24 +6,9 @@ (send-message system 'print "Hello, what is your name?") (send-message system 'read (make-actor (lambda (self . message) - (print message) (match message ((name) (send-message system 'print "Hello, " name "!") 'done))))) (send-message-later system 10 'print "Boo!")) - -(let loop ((args (cdr (argv))) - (host "localhost") - (port 8000)) - (match args - (((or "-h" "--help")) - (print "Usage: simple_test [ -h ] [ --port PORT ] [ --hostname host ]")) - (((or "-p" "--port") pstr rest ...) - (loop rest host (string->number pstr))) - (("--hostname" hstr rest ...) - (loop rest hstr port)) - (() - (print "-- Starting SAM on " host ":" port " --\n") - (boot-sam host port main-beh))))