02 Message - OLD
Important
The message structure goes in a separate file called “ic-msg.rkt”.The message structure gets its name abbreviated to “ic-msg” because we type it a lot.
A IC-Msg is a structure.
(make-ic-msg Number Number Color-String)
Interpretation:
(make-ic-msg from to col)
from: the id of the world sending the messageto: the id of the world the message is intended forcol: the new color that world is to show
The structure definition for a message should go in a separate file so
we can use advanced #lang racket features to make it simple to send.
Instructions
-
Open a new, empty file (new tab; Control-T).
-
Change the new file to Racket language mode. Go to the menu “Language”, select “Choose Language…” and then “The Racket Language”.
-
The file should contain only these three lines below:
#lang racket (provide (all-defined-out)) (define-struct ic-msg (from to col) #:prefab) -
Save the file in the same folder that contains your other code. (This works like the
posn-util.rktfile.)
After saving, verify that the file says “Determine language from source” in the bottom left part of the window. Not “Beginning Student”.
Checkpoint
Verify that you can and use your message structure in your main file.
Go back to your main file and add the following code snippet. You must save your file before you will be able to run it.
(require "ic-msg.rkt")
(define ex1 (make-ic-msg 1 3 "blue"))
(ic-msg-col ex1) ;; should show "blue"
Common Problems
- The file must be in Racket language mode. (Menu: Language -> Choose Language … -> The Racket Language)
- There should be no space between the
#:andprefab. - This file should not begin with
(require picturing-programs).
If you have problems creating the file yourself, download it using Save link as… (ic-msg.rkt).