(import actors)

(enable-trace)

(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)