From: Tim Vaughan Date: Sun, 7 Jul 2019 22:09:05 +0000 (+0200) Subject: Improved examples. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;ds=sidebyside;h=f1da9dd563657b366b9918d5d5e6b61c1e59c43b;p=actors.git Improved examples. --- diff --git a/actors.scm b/actors.scm index 633445a..263acdc 100644 --- a/actors.scm +++ b/actors.scm @@ -9,6 +9,8 @@ (define actor-table (make-hash-table)) (define (make-actor-with-address address behaviour) + (if trace-enabled + (print "Making actor with address " address)) (hash-table-set! actor-table address behaviour) address) @@ -33,7 +35,10 @@ (let ((value (apply behaviour (cons address message)))) (case value ((sleep) 'do-nothing) - ((done) (hash-table-delete! actor-table address)) + ((done) + (if trace-enabled + (print "Deleting actor " address)) + (hash-table-delete! actor-table address)) (else (if trace-enabled (print "Updating behaviour of " address)) diff --git a/testing_factorial1.scm b/testing_factorial1.scm index 09aafda..6600661 100644 --- a/testing_factorial1.scm +++ b/testing_factorial1.scm @@ -1,5 +1,7 @@ (load "actors.scm") +(define trace-enabled #t) + (define factorial (make-actor-with-address 'factorial (lambda (self customer . message) diff --git a/testing_factorial2.scm b/testing_factorial2.scm index 58e4c5c..363b61b 100644 --- a/testing_factorial2.scm +++ b/testing_factorial2.scm @@ -1,5 +1,7 @@ (load "actors.scm") +(define trace-enabled #t) + (define factorial (make-actor-with-address 'factorial (lambda (self customer n) diff --git a/testing_factorial3.scm b/testing_factorial3.scm index b3450aa..1cb9dd9 100644 --- a/testing_factorial3.scm +++ b/testing_factorial3.scm @@ -12,8 +12,8 @@ (lambda (self m) (send-message customer (* n m)) 'done)))) - (send-message self fact-acc (- n 1)) - 'sleep))))) + (send-message self fact-acc (- n 1)))) + 'sleep))) (define println (make-actor-with-address 'println @@ -22,4 +22,5 @@ 'sleep))) (send-message factorial println 5) +(send-message factorial println 7) (run)