Improved examples.
authorTim Vaughan <tgvaughan@gmail.com>
Sun, 7 Jul 2019 22:09:05 +0000 (00:09 +0200)
committerTim Vaughan <tgvaughan@gmail.com>
Sun, 7 Jul 2019 22:09:05 +0000 (00:09 +0200)
actors.scm
testing_factorial1.scm
testing_factorial2.scm
testing_factorial3.scm

index 633445a..263acdc 100644 (file)
@@ -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)
 
         (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))
index 09aafda..6600661 100644 (file)
@@ -1,5 +1,7 @@
 (load "actors.scm")
 
+(define trace-enabled #t)
+
 (define factorial
   (make-actor-with-address 'factorial
    (lambda (self customer . message)
index 58e4c5c..363b61b 100644 (file)
@@ -1,5 +1,7 @@
 (load "actors.scm")
 
+(define trace-enabled #t)
+
 (define factorial
   (make-actor-with-address 'factorial
    (lambda (self customer n)
index b3450aa..1cb9dd9 100644 (file)
@@ -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)