From: Tim Vaughan Date: Sun, 7 Jul 2019 20:02:14 +0000 (+0200) Subject: Added second example using actors to capture state. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=89a29ed508c0ab3d5eafdf81ed9f8957906381c8;p=actors.git Added second example using actors to capture state. --- diff --git a/testing_factorial2.scm b/testing_factorial2.scm new file mode 100644 index 0000000..58e4c5c --- /dev/null +++ b/testing_factorial2.scm @@ -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)