From: Christopher Allan Webber Date: Wed, 4 Jan 2017 16:28:18 +0000 (-0600) Subject: actors: Rename msg-receive, msg-val to mbody-receive, mbody-val. X-Git-Tag: v0.4.0~25 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=2785c244a09fc008488385b10053ef854fb27c34;p=8sync.git actors: Rename msg-receive, msg-val to mbody-receive, mbody-val. * 8sync/actors.scm (mbody-receive, mbody-val): Rename from msg-receive, msg-val. Update all callers. --- diff --git a/8sync/actors.scm b/8sync/actors.scm index 1f5bd3c..8e1b504 100644 --- a/8sync/actors.scm +++ b/8sync/actors.scm @@ -73,7 +73,7 @@ <- <-* <-wait <-wait* <-reply <-reply* <-reply-wait <-reply-wait* - call-with-message msg-receive msg-val + call-with-message mbody-receive mbody-val run-hive bootstrap-message @@ -715,21 +715,21 @@ for debugging" argument. Similar to call-with-values in concept." (apply proc message (message-body message))) -;; (msg-receive (<- bar baz) +;; (mbody-receive (<- bar baz) ;; (baz) ;; basil) -;; Emacs: (put 'msg-receive 'scheme-indent-function 2) +;; Emacs: (put 'mbody-receive 'scheme-indent-function 2) ;; @@: Or receive-msg or receieve-message or?? -(define-syntax-rule (msg-receive arglist message body ...) +(define-syntax-rule (mbody-receive arglist message body ...) "Call body with arglist (which can accept arguments like lambda*) applied from the message-body of message." (call-with-message message (lambda* arglist body ...))) -(define (msg-val message) +(define (mbody-val message) "Retrieve the first value from the message-body of message. Like single value return from a procedure call. Probably the most common case when waiting on a reply from some action invocation." diff --git a/demos/actors/robotscanner.scm b/demos/actors/robotscanner.scm index 0b32b36..1fd3c88 100644 --- a/demos/actors/robotscanner.scm +++ b/demos/actors/robotscanner.scm @@ -223,13 +223,13 @@ (address-actor-id room))) ;; Find all droids in this room and exterminate the infected ones. - (msg-receive (_ #:key list-droids droid-ids #:allow-other-keys) + (mbody-receive (_ #:key list-droids droid-ids #:allow-other-keys) (<-wait room 'list-droids) (for-each (lambda (droid-id) (cond ;; Looks like it's infected - ((msg-val (<-wait droid-id 'infection-expose)) + ((mbody-val (<-wait droid-id 'infection-expose)) ;; Inform that it's infected (<- overseer 'transmission #:text (format #f "~a found to be infected... taking out" @@ -238,7 +238,7 @@ ;; Keep firing till it's dead. (let ((still-alive #t)) (while still-alive - (msg-receive (response #:key alive #:allow-other-keys) + (mbody-receive (response #:key alive #:allow-other-keys) (<-wait droid-id 'get-shot) (<- overseer 'transmission #:text (droid-status-format response)) @@ -253,7 +253,7 @@ droid-ids)) ;; Switch to next room, if there is one. - (set! room (msg-val (<-wait room 'get-next-room)))) + (set! room (mbody-val (<-wait room 'get-next-room)))) ;; Good job everyone! Shut down the operation. (<- overseer 'transmission diff --git a/doc/8sync-new-manual.org b/doc/8sync-new-manual.org index ebbd13a..5239b3b 100644 --- a/doc/8sync-new-manual.org +++ b/doc/8sync-new-manual.org @@ -710,8 +710,8 @@ into a micromanager. "Pester direct report until they're done with their task." (display "manager> Are you done yet???\n") (let ((still-working - (msg-val (<-wait (manager-direct-report manager) - 'done-yet?)))) + (mbody-val (<-wait (manager-direct-report manager) + 'done-yet?)))) (if still-working (begin (display "manager> Harumph!\n") (8sleep 1) @@ -725,9 +725,10 @@ We've appended a micromanagement loop here... but what's going on? "<-wait", as it sounds, waits for a reply, and returns a reply message. In this case there's a value in the body of the message we want, -so we pull it out with msg-val. +so we pull it out with mbody-val. (It's possible for a remote actor to return multiple values, in which -case we'd want to use msg-receive, but that's a bit more complicated.) +case we'd want to use mbody-receive, but that's a bit more +complicated.) Of course, we need to update our worker accordingly as well. @@ -779,6 +780,15 @@ Ka-poof! ** COMMENT Websockets * Addendum +** Recommended .emacs additions + +In order for =mbody-receive= to indent properly, put this in your +.emacs: + +#+BEGIN_SRC emacs-lisp +(put 'mbody-receive 'scheme-indent-function 2) +#+END_SRC + ** 8sync and Fibers One other major library for asynchronous communication in Guile-land diff --git a/tests/test-actors.scm b/tests/test-actors.scm index ad81142..4d7ec4b 100644 --- a/tests/test-actors.scm +++ b/tests/test-actors.scm @@ -79,13 +79,13 @@ (define* (antsy-caller-pester-rep actor message #:key who-to-call) (~display "customer> I'm calling customer service about this!\n") - (msg-receive (first-reply #:key msg) + (mbody-receive (first-reply #:key msg) (<-wait who-to-call 'field-call) (if (message-auto-reply? first-reply) (~display "customer> Whaaaaat? I can't believe I got voice mail!\n") (begin (~format "*customer hears*: ~a\n" msg) - (msg-receive (second-reply #:key *auto-reply*) + (mbody-receive (second-reply #:key *auto-reply*) (<-reply-wait first-reply #:msg "Yes, it didn't work, I'm VERY ANGRY!") (if (message-auto-reply? second-reply) @@ -97,7 +97,7 @@ (define (rep-field-call actor message) (~display "good-rep> Hm, another call from a customer...\n") - (msg-receive (reply #:key msg) + (mbody-receive (reply #:key msg) (<-reply-wait message #:msg "Have you tried turning it off and on?") (~format "*rep hears*: ~a\n" msg) (~display "good-rep> I'm sorry, that's all I can do for you.\n")))