10 Questions I

Steps 01-05 questions to clarify understanding.
  1. What error message do you get when your ic-msg.rkt file is not in the same folder as your main Racket file?

  2. If you download the ic-msg.rkt file three times, do you see any messages from your browser? Do you end up with one file or three? How did you find out?

  3. Suppose you have downloaded all-good.rkt. You delete the #:prefab part and save the file. That doesn’t work as a message, so want the original back. You download the file again. Does this work? Try it and explain what happens and why.

     (require "all-good.rkt")
     (check-expect (make-good 30 40 50) (make-good 30 40 50))
    
  4. Suppose you have ic-msg.rkt correctly written and saved on your computer. You open a new untitled Racket document, type the following line, and run it. What happens? Explain.

     (require "ic-msg.rkt")
    
  5. Will requiring a file called “Walkthough IC Message.rkt” work? Try it and report what happens.

  6. Will requiring a file called “Walkthough-IC-Message.rkt” work? Try it and report what happens.

  7. Your key handler wants to change the id number of your world.

    1. Can you do this without sending a message? Explain.
    2. Can you do this by sending a message? Explain.

Understanding Data Structures

(define-struct ic (id col))
(define-struct ic-msg (from to col))
  1. When we talk about “the world (make-ic 8 "blue")”, is that a model or a message?

  2. Suppose the ic from the previous question is stored in a variable called xxx. How do you get the “blue” out of that variable?

  3. Store (make-ic-msg 2 3 "pink") in a variable called yyy. Fill in the blanks with code to make the checks pass.

     (check-expect ___________________ 3)
    
     (check-expect ___________________ "pink")
    
  4. With the variables xxx and yyy from above, what code makes a new model with the id from xxx and the col from yyy?

Handler Analysis I

Use the function below as a receive handler to answer the questions that follow.

(define (receive-h model my-msg)
   (cond [(= (ic-msg-from my-msg) 0)
          (make-ic (random 100) (ic-col model))]
         [(= (ic-msg-to my-msg) (ic-id model))
          (make-ic (ic-id model) (ic-msg-col my-msg))]
         [else model]))
  1. The world (make-ic 12 "light blue") receives the message (make-ic-msg 1 2 "orange"). What happens?
  2. The world (make-ic 34 "light orange") receives the message (make-ic-msg 56 34 "light blue"). What happens?
  3. The world (make-ic 56 "light blue") receives the message (make-ic-msg 0 78 "pink"). What happens?
  4. The world (make-ic 91 "light blue") receives the message (make-ic-msg 91 0 "purple"). What happens?
  5. In at least two sentences, describe what this receive handler does.