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
-
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 handlerkh.- Write the signature for the key handler that you will use.
- Write the key handler
kh.
-
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 thenumfield of the message.- Make up a name for the function to manage this and write its signature.
- Write the part of the function to perform this task.
-
When the string part of the message is
"sum", thennumfield is actually a list of numbers. The receiver should set itsstateto the sum of those numbers.Write code to add to the function from the previous section.