(if (null? behaviour)
(print "Warning: discarded message " message " to unknown actor " address)
(let ((value (apply behaviour (cons address message))))
- (match value
- ('done (hash-table-delete! actor-table address))
- ('sleep 'do-nothing)
+ (case value
+ ((done) (hash-table-delete! actor-table address))
+ ((sleep) 'do-nothing)
(else
- hash-table-set! actor-table address value))))))
+ (if trace-enabled
+ (print "Updating behaviour of " address))
+ (hash-table-set! actor-table address value)))))))
;;;
;;; FIFO queue implementation
--- /dev/null
+(load "actors.scm")
+
+(define trace-enabled #t)
+
+(define ((make-counter-behaviour value) self customer . args)
+ (match args
+ (('get) (send-message customer value) 'sleep)
+ (('inc delta) (make-counter-behaviour (+ value delta)))))
+
+(define println
+ (make-actor-with-address 'println
+ (lambda (self . message)
+ (apply print message)
+ 'sleep)))
+
+(define counter0 (make-actor (make-counter-behaviour 0)))
+
+(send-and-run counter0 println 'get)
+(send-message counter0 println 'inc 3)
+(send-message counter0 println 'get)
+(send-message counter0 println 'inc 2)
+(send-and-run counter0 println 'get)