Added third factorial example.
authorTim Vaughan <tgvaughan@gmail.com>
Sun, 7 Jul 2019 21:06:27 +0000 (23:06 +0200)
committerTim Vaughan <tgvaughan@gmail.com>
Sun, 7 Jul 2019 21:06:27 +0000 (23:06 +0200)
actors.scm
testing_factorial3.scm [new file with mode: 0644]

index 4ae01ed..fa6f1bb 100644 (file)
@@ -1,6 +1,6 @@
 (import srfi-69 matchable)
 
-(define trace-enabled #t)
+(define trace-enabled #f)
 
 ;;;
 ;;; Actor creation
diff --git a/testing_factorial3.scm b/testing_factorial3.scm
new file mode 100644 (file)
index 0000000..b3450aa
--- /dev/null
@@ -0,0 +1,25 @@
+(load "actors.scm")
+
+(define trace-enabled #t)
+
+(define factorial
+  (make-actor-with-address
+   'factorial
+   (lambda (self customer n)
+     (if (= n 0)
+         (send-message customer 1)
+         (let ((fact-acc (make-actor
+                          (lambda (self m)
+                            (send-message customer (* n m))
+                            'done))))
+           (send-message self fact-acc (- n 1))
+           'sleep)))))
+
+(define println
+  (make-actor-with-address 'println
+   (lambda (self . message)
+     (apply print message)
+     'sleep)))
+
+(send-message factorial println 5)
+(run)