05 Receive H

The receive handler’s job is to update a world’s model in response to receiving a message. The signature of the receive handler is:

receive-h: model message -> model

In a fancy multi-player system, your world would only receive messages that were intended for you.

We are using a very “generic” server, where every world gets messages for every other world, so the first thing you should do in your receive handler is to see if your own id matches the “to” id in the message.

Examples

This example is from the perspective of world 1, which is “orange” initially. A message comes from world 2 to world 1 with the color “light blue”. World 1 should react by changing color.

(check-expect (receive-h (make-ic 1 "orange")
                         (make-ic-msg 2 1 "light blue"))
              (make-ic 1 "light blue"))

Note that other worlds will also “hear” the same message, and should ignore it. The check below shows that a “green” world 3 does not react to the same message.

(check-expect (receive-h (make-ic 3 "light green")
                         (make-ic-msg 2 1 "light blue"))
              (make-ic 3 "light green"))

Coding

You should have enough coding experience now to write the code for the receive handler.