10 Questions I
-
What error message do you get when your
ic-msg.rkt
file is not in the same folder as your main Racket file? -
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?
-
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))
-
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")
-
Will requiring a file called “Walkthough IC Message.rkt” work? Try it and report what happens.
-
Will requiring a file called “Walkthough-IC-Message.rkt” work? Try it and report what happens.
-
Your key handler wants to change the
id
number of your world.- Can you do this without sending a message? Explain.
- Can you do this by sending a message? Explain.
Understanding Data Structures
(define-struct ic (id col))
(define-struct ic-msg (from to col))
-
When we talk about “the world
(make-ic 8 "blue")
”, is that a model or a message? -
Suppose the
ic
from the previous question is stored in a variable calledxxx
. How do you get the “blue” out of that variable? -
Store
(make-ic-msg 2 3 "pink")
in a variable calledyyy
. Fill in the blanks with code to make the checks pass.(check-expect ___________________ 3) (check-expect ___________________ "pink")
-
With the variables
xxx
andyyy
from above, what code makes a new model with theid
fromxxx
and thecol
fromyyy
?
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]))
- The world
(make-ic 12 "light blue")
receives the message(make-ic-msg 1 2 "orange")
. What happens? - The world
(make-ic 34 "light orange")
receives the message(make-ic-msg 56 34 "light blue")
. What happens? - The world
(make-ic 56 "light blue")
receives the message(make-ic-msg 0 78 "pink")
. What happens? - The world
(make-ic 91 "light blue")
receives the message(make-ic-msg 91 0 "purple")
. What happens? - In at least two sentences, describe what this receive handler does.