U WS 04

A world model has an id number and another number called “state”. A message consists of the id of the sender and another number and a string.

(define-struct ww (id state)) ;; World Model
(define-struct mm (id num s)) ;; Message
  1. Hitting a key adds one to the world’s id and causes a random number 1 through 10 to be be sent along with the string "rng". Use the original id of the world for the id in the message. All of this action should occur in the key handler kh.

    1. Write the signature for the key handler that you will use.
    2. Write the key handler kh.
  2. When the string part of the message is the string "reset" and the receiving world did not just send the message, change the id of the receiving world to the number in the num field of the message.

    1. Make up a name for the function to manage this and write its signature.
    2. Write the part of the function to perform this task.
  3. When the string part of the message is "sum", then num field is actually a list of numbers. The receiver should set its state to the sum of those numbers.

    Write code to add to the function from the previous section.

Last modified August 18, 2023: 2022-2023 End State (7352e87)