actors: Remove define-simple-actor, add define-actor.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Wed, 4 Jan 2017 17:41:30 +0000 (11:41 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Wed, 4 Jan 2017 17:41:30 +0000 (11:41 -0600)
define-simple-actor wasn't very useful, whereas define-actor is
moderately helpful.

* 8sync/actors.scm (define-simple-actor): Remove.
(define-actor): New macro.

* demos/actors/robotscanner.scm:
* demos/actors/simplest-possible.scm:
* tests/test-actors.scm: Convert to use define-simple-actor instead of
define-actor.

8sync/actors.scm
demos/actors/robotscanner.scm
demos/actors/simplest-possible.scm
tests/test-actors.scm

index 8e1b504b9378e3f5ff5ab4e239018459cb2ced3f..1d8e6023aa3b19bcb8350e4ee35d759cc3f59021 100644 (file)
@@ -51,7 +51,7 @@
 
             build-actions
 
-            define-simple-actor
+            define-actor
 
             <hive>
             make-hive
@@ -395,10 +395,13 @@ to come after class definition."
 ;;; Actor utilities
 ;;; ===============
 
-(define-syntax-rule (define-simple-actor class action ...)
-  (define-class class (<actor>)
+(define-syntax-rule (define-actor class inherits
+                      (action ...)
+                      slots ...)
+  (define-class class inherits
     (actions #:init-value (build-actions action ...)
-             #:allocation #:each-subclass)))
+             #:allocation #:each-subclass)
+    slots ...))
 
 \f
 ;;; The Hive
index 1fd3c88b96ad7b5d0c81b38dbce05b6096d8d372..5dd5d5e13d6fb484daa14a0602db410a69c778f5 100644 (file)
     (5 0)
     (2 1)))
 
-(define-simple-actor <overseer>
-  (init-world
-   (lambda (actor message)
-     ;; Porting mostly straight up from super-imperative XUDD code.
-     (define previous-room #f)
-     (define first-room #f)
-
-     ;; Set up all rooms
-     (for-each
-      (match-lambda
-        ((clean-droids infected-droids)
-         ;; Create this room
-         (define room (create-actor* actor <warehouse-room> "room"))
-         (define* (init-droid #:key infected)
-           (define droid (create-actor* actor <droid> "droid"
-                                        #:infected infected
-                                        #:room room))
-           (<-wait droid 'register-with-room))
-
-         ;; Link rooms.
-         ;; Couldn't this just be folded into the warehouse room init?
-         ;; I guess it stress tests more the message sending process
-         (when previous-room
-           (<- previous-room 'set-next-room
-               #:id room)
-           (<- room 'set-previous-room
-               #:id previous-room))
-
-         ;; Set up clean droids in the room
-         (for-each
-          (lambda _
-            (init-droid #:infected #f))
-          (iota clean-droids))
-
-         ;; Set up infected droids in the room
-         (for-each
-          (lambda _
-            (init-droid #:infected #t))
-          (iota clean-droids))
-
-         (set! previous-room room)
-         (if (not first-room)
-             (set! first-room room))))
-      room-structure)
-
-     ;; Add security robot
-     (let ((security-robot
-            (create-actor actor <security-robot>)))
-       (<- security-robot 'begin-mission
-           #:starting-room first-room
-           #:overseer (actor-id actor)))))
-
-  (transmission
-   (lambda* (actor message #:key text)
-     (display text)
-     (newline))))
+(define-actor <overseer> (<actor>)
+  ((init-world
+    (lambda (actor message)
+      ;; Porting mostly straight up from super-imperative XUDD code.
+      (define previous-room #f)
+      (define first-room #f)
+
+      ;; Set up all rooms
+      (for-each
+       (match-lambda
+         ((clean-droids infected-droids)
+          ;; Create this room
+          (define room (create-actor* actor <warehouse-room> "room"))
+          (define* (init-droid #:key infected)
+            (define droid (create-actor* actor <droid> "droid"
+                                         #:infected infected
+                                         #:room room))
+            (<-wait droid 'register-with-room))
+
+          ;; Link rooms.
+          ;; Couldn't this just be folded into the warehouse room init?
+          ;; I guess it stress tests more the message sending process
+          (when previous-room
+            (<- previous-room 'set-next-room
+                #:id room)
+            (<- room 'set-previous-room
+                #:id previous-room))
+
+          ;; Set up clean droids in the room
+          (for-each
+           (lambda _
+             (init-droid #:infected #f))
+           (iota clean-droids))
+
+          ;; Set up infected droids in the room
+          (for-each
+           (lambda _
+             (init-droid #:infected #t))
+           (iota clean-droids))
+
+          (set! previous-room room)
+          (if (not first-room)
+              (set! first-room room))))
+       room-structure)
+
+      ;; Add security robot
+      (let ((security-robot
+             (create-actor actor <security-robot>)))
+        (<- security-robot 'begin-mission
+            #:starting-room first-room
+            #:overseer (actor-id actor)))))
+
+   (transmission
+    (lambda* (actor message #:key text)
+      (display text)
+      (newline)))))
 
 
 ;;; A room full of robots.
 
 
 ;;; Security robot... designed to seek out and destroy infected droids.
-(define-simple-actor <security-robot>
-  (begin-mission security-robot-begin-mission))
+(define-actor <security-robot> (<actor>)
+  ((begin-mission security-robot-begin-mission)))
 
 (define* (security-robot-begin-mission actor message
                                        #:key starting-room overseer)
index 7743ccb3b8bcccf8ec1b34babe1aeb3aa5039301..58921fe4d7f3acc253903af26ff2518de32e049b 100644 (file)
 (use-modules (8sync actors)
              (oop goops))
 
-(define-simple-actor <emo>
-  (greet-proog
-   (lambda (actor message target)
-     (display "emo> What's next, Proog?\n")
-     (<- target 'greet-emo))))
+(define-actor <emo> (<actor>)
+  ((greet-proog
+    (lambda (actor message target)
+      (display "emo> What's next, Proog?\n")
+      (<- target 'greet-emo)))))
 
-(define-simple-actor <proog>
-  (greet-emo
-   (lambda (actor message)
-     (display "proog> Listen, Emo!  Listen to the sounds of the machine!\n"))))
+(define-actor <proog> (<actor>)
+  ((greet-emo
+    (lambda (actor message)
+      (display "proog> Listen, Emo!  Listen to the sounds of the machine!\n")))))
 
 (define hive (make-hive))
 (define our-emo (bootstrap-actor hive <emo>))
index 4d7ec4b3d1a2fc6f99cedfbdcb1d82e594cce960..0b9adb503e34a591a9b62c336257dd96db266a8e 100644 (file)
@@ -74,8 +74,8 @@
 ;;; Test reply / autoreply
 ;;; ======================
 
-(define-simple-actor <antsy-caller>
-  (pester-rep (wrap-apply antsy-caller-pester-rep)))
+(define-actor <antsy-caller> (<actor>)
+  ((pester-rep (wrap-apply antsy-caller-pester-rep))))
 
 (define* (antsy-caller-pester-rep actor message #:key who-to-call)
   (~display "customer> I'm calling customer service about this!\n")
@@ -92,8 +92,8 @@
                 (~display "customer> Well then!  Harumph.\n")
                 (error "Not an autoreply?  What's going on here...")))))))
 
-(define-simple-actor <diligent-rep>
-  (field-call (wrap-apply rep-field-call)))
+(define-actor <diligent-rep> (<actor>)
+  ((field-call (wrap-apply rep-field-call))))
 
 (define (rep-field-call actor message)
   (~display "good-rep> Hm, another call from a customer...\n")
     (~format "*rep hears*: ~a\n" msg)
     (~display "good-rep> I'm sorry, that's all I can do for you.\n")))
 
-(define-simple-actor <lazy-rep>
-  (field-call
-   (lambda (actor message)
-     (~display "lazy-rep> I'm not answering that.\n"))))
+(define-actor <lazy-rep> (<actor>)
+  ((field-call
+    (lambda (actor message)
+      (~display "lazy-rep> I'm not answering that.\n")))))
 
 (let* ((hive (make-hive))
        (customer (bootstrap-actor* hive <antsy-caller> "antsy-caller"))
@@ -140,8 +140,8 @@ customer> Whaaaaat?  I can't believe I got voice mail!\n"
 \f
 ;;; Cleanup tests
 
-(define-simple-actor <cleanly>
-  (*cleanup* test-call-cleanup))
+(define-actor <cleanly> (<actor>)
+  ((*cleanup* test-call-cleanup)))
 
 (define (test-call-cleanup actor message)
   (speak "Hey, I'm cleanin' up here!\n"))
@@ -165,11 +165,11 @@ customer> Whaaaaat?  I can't believe I got voice mail!\n"
 ;; The exploder self-destructs, even though run-hive has cleanup
 ;; disabled, because it cleans up on self-destruct.
 
-(define-simple-actor <exploder>
-  (explode (lambda (exploder message)
-             (speak "POOF\n")
-             (self-destruct exploder)))
-  (*cleanup* (lambda _ (speak "Cleaning up post-explosion\n"))))
+(define-actor <exploder> (<actor>)
+  ((explode (lambda (exploder message)
+              (speak "POOF\n")
+              (self-destruct exploder)))
+   (*cleanup* (lambda _ (speak "Cleaning up post-explosion\n")))))
 
 (with-fresh-speaker
  (let ((hive (make-hive)))