(import actors)

(enable-trace)

(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)
(send-message factorial println 7)
(run)