Added second example using actors to capture state.
authorTim Vaughan <tgvaughan@gmail.com>
Sun, 7 Jul 2019 20:02:14 +0000 (22:02 +0200)
committerTim Vaughan <tgvaughan@gmail.com>
Sun, 7 Jul 2019 20:02:49 +0000 (22:02 +0200)
testing_factorial2.scm [new file with mode: 0644]

diff --git a/testing_factorial2.scm b/testing_factorial2.scm
new file mode 100644 (file)
index 0000000..58e4c5c
--- /dev/null
@@ -0,0 +1,22 @@
+(load "actors.scm")
+
+(define factorial
+  (make-actor-with-address 'factorial
+   (lambda (self customer n)
+     (let ((fact_svc (make-actor
+                      (lambda (self n acc)
+                        (cond
+                         ((> n 0) (send-message self (- n 1) (* acc n)) 'sleep)
+                         (else (send-message customer acc) 'done))))))
+       (send-message fact_svc n 1)
+       'sleep))))
+
+(define println
+  (make-actor-with-address 'println
+   (lambda (self . message)
+     (apply print message)
+     'sleep)))
+
+(send-message factorial println 5)
+(send-message factorial println 7)
+(run)