====== CS101 Spring 2011 ======
~~NOTOC~~
===== Lab #1 =====
==== Introducing the DrRacket IDE ====
The main purpose of this initial laboratory exercise is to acquaint you with
* your new CS account,
* the Linux operating system,
* the DrRacket IDE, and
* the procedure for submitting your work electronically.
You will create your first program within the cs101 course directory of your CS account. The program you cut and paste will itself be very simple, because the goal of this lab is to learn to use your CS account to create, run, print, and submit your work electronically for grading.
**How to get started**
- Use your new CS account to login to one of the Linux-based machines. You will be able to create your own directory structure within this account, and you will be able to save and retrieve your work between logins. \\ \\
- Bring up a terminal window by clicking on the terminal icon in the toolbar located at the bottom center of your desktop. \\ \\
- Create a new directory named cs101 in your home directory, and set the permissions so that only you can access the contents of this directory. To do this, type the following commands, pressing return after each command, at the Linux prompt ($): \\ \\ '' mkdir cs101'' \\ '' chmod 700 cs101'' \\ \\
- Create a new directory for this lab in your cs101 directory by entering the following at the Linux prompt ($): \\ \\ '' cd cs101'' \\ '' mkdir lab1'' \\ \\
- To launch DrRacket, enter the following command at the Linux prompt: \\ \\ '' drracket &'' \\ \\
- When DrRacket loads, you will be presented with a window that is divided into two main frames: the //definitions window// (top half) and the //interactions window// (bottom half). \\ \\
- From the Language menu along DrRacket's menu bar, select ''Choose Language...''. In the left column, make sure the arrow head to the left of ''How to Design Programs'' is pointing downwards. If the arrow is not pointing downwards, click on it. This will cause a list of language levels to appear. Click on ''Beginning Student Language''. Click the OK button bottom right to save this selection.\\ \\
- To make BSL your default language, click on the **Run** button at the top of the screen. The interactions window will display the lines shown below:
Welcome to DrRacket, version 5.0.1 [3m].
Language: Beginning Student.
>
Now you are ready to begin programming! Note that you will need to follow steps 7-8 when setting up DrRacket on your own computer, too.\\ \\
** Your first program **
For this lab, you will create a program by copy/pasting the following code into the definitions pane of DrRacket. In future labs and assignments, you will type in your own code, but for the purposes of this lab you are given a head start. The lines below that start with semicolons ('';;'') are not evaluated by the computer...they are //comments//, intended for human readers only. The lines that do not start with '';;'' are expressions that are evaluated by DrRacket.
Copy and paste the following lines of code into the DrRacket Definitions pane:
(require 2htdp/universe)
(require 2htdp/image)
;; CS101 Lab 1
;; Name: <==== Type your own name here in place of the text in <>s
;; Description: evaluating different types of expressions, keeping in mind that
;; primitive function invocations are expressions
;; All the primitive (atomic) data types are expressions that evaluate to
;; themselves:
"1. Numbers are a type of atomic data:"
2
4.678
3/5
" "
"2. Strings are any sequence of characters enclosed in quotation marks:"
"Hello world"
"cat"
"45 plus three is 48"
" "
"3. Symbols are any sequence of non-space characters preceded by an apostrophe:"
'thisisasymbol
'34
'()
" "
"4. Booleans are the sequence of letters (NOT in quotation marks) true or false:"
false
true
" "
"5. The empty list, represented by the word empty:"
empty
" "
"6. Built-in (aka primitive) functions evaluate to themselves:"
+
*
<
" "
"7. Images are a type of primitive data inserted as .gif or .jpg files or
shapes drawn using primitive functions defined in the image library:"
"images must be inserted within DrRacket"
;; Function invocations are expressions that begin with an open parenthesis,
;; followed immediately by the function name, followed by the appropriate
;; number and type of arguments.
;;
;; --the following function invocation (+ ...) adds multiple numbers from
;; left to right, producing a single number
(+ 40 1 1)
;; --the following function invocation (string-append ...) appends multiple strings
;; from left to right, producing a single string
(string-append "Computer " "Science")
;; --the following function invocation (> num num) compares two numbers,
;; producing a boolean (true or false)
(> 42 9)
;; --the following function invocation draws a filled-in, red circle
;; --the result is a shape (a type of image)
(circle 10 "solid" "red");
;; Images may be combined
;; --the following function invocation draws a circle on top of a square
;; --the result is an image
(overlay (rectangle 20 20 "solid" "blue")
(circle 5 "solid" "red"))
;; Scenes are a type of data, an image of an empty window on the screen
;; --the following function invocation creates an empty window (an image)
(empty-scene 100 100)
;; Images may be placed within scenes
;; --the following function invocation places a circle on top of an empty scene
;; --the result is another scene containing a red circle
(place-image (circle 10 "solid" "red")
25 25
(empty-scene 100 100))
- Fill in your name where appears in the comments at the top of the program. \\ \\
- Save your program by clicking the **Save** button at the top of the window. A drop-down window will display a representation of your Linux directory. Save the file inside your Lab1 folder as ''lab1.rkt''. \\ \\
- Run your program by clicking the **Run** button. \\ \\
- If there is a syntax error somewhere in your code, DrRacket will generate a syntax error. To see what a syntax error looks like, remove the right parentheses from the end of one of the expressions (a line that does not start with ;;) and click the **Run** button. Notice how the error message appears in a red font in the interactions pane. \\ \\
- We encourage you to experiment with this program. The comments describe what the following expression does, so read carefully, then play around by changing the expressions, save, and re-run. See if you get the results you expect. Be daring! In the worst case, you can always recopy the code above back into DrRacket. If you get an error, ask one of the coaches or your professor to explain the reason for the error.\\ \\
- When your program successfully runs, show it to your lab instructor or one of the lab coaches and follow the submit procedure detailed below. \\ \\
**Submitting your work**
You are being asked to submit this lab so that you know how to submit assignments in the future. No lab other than lab1 will be submitted, you will only get credit for the lab if you are checked off by a coach or your professor. From a terminal window, type the following commands at the Linux prompt:
cd cs101
submit101 lab1
**Log out**
When you are done, close DrRacket by choosing ''Quit'' from the **File** menu, and then locate the logout button on the menu bar. Click on the logout button (red arrow pointing through an open door). Choose "Logout..." and then click "Yes" when prompted. Always remember to log out when you are done using the system, to ensure that no one else uses your account.