1 Administrative Hoops
2 Starting up Dr Racket, registering for a handin account
3 Using Dr Racket
4 Elements of Racket
5 Exercises
5.1 Simple data
5.2 Mixed groupings of simple data

Lab 1, CSC430, Winter 2011

1 Administrative Hoops

First, you need to join the google group by visiting the URL on the course syllabus. Request to join, and I’ll approve the request. I’d just invite you all, but the problem is that Google won’t allow me to invite that many people, so we’re stuck with this.

2 Starting up DrRacket, registering for a handin account

I’ve installed an up-to-date version of DrRacket in my account. In order to run it on one of the Lab machines (booted in Linux), execute
  ~clements/drracket
from a terminal window. Let me know if you have any trouble with this.

Next you’ll need to install the handin plugin. Follow the instructions on the course syllabus.

After restarting DrRacket, you must register a handin account with the handin server. choose the Manage CPE430 User Account... menu item from the leftmost menu. Follow the dialog to create a new user account. Note that the "ID number" field is ignored but must be non-blank.

*Please* use a good e-mail address; the e-mail address you enter here will be my principal means of contacting you. You are responsible for checking this e-mail address daily.

Next, we need to check that handin is working properly. Type some text in the topmost window. This is called the "definitions" window. Click on the handin button, and make sure that you can hand in successfully. Note that you may always submit as many times as you like; later submissions overwrite earlier ones, so you don’t need to worry about submitting an early incomplete solution. However, you must be careful that your final submission contains all of your work.

Now, mess up the text in the definitions. Then, using the Handin button again, retrieve the text you submitted earlier. This should now be different from your changed text.

3 Using DrRacket

Next, erase the existing junk and type a short legal Racket program in the definitions window. How about this one:

  #lang plai
  
  (+ 3 4)

Now, click on execute. The lower window (called the "interactions" window) should show success.

In the interactions window, we can also evaluate expressions. Type (+ 4 5) and hit return.

Next, we need to see how tests work.

In the definitions window, type

  (test (* 4 13) 52)

Click Run. What do you see?

4 Elements of Racket

What else can we represent, besides numbers?

Well, it turns out that we also have booleans:

  • true

  • false

  • (or false true)

These are all expressions. Make sure they evaluate to the expected results. Write a test case for the third one. That is, something like:

  (test (or false true) <expected result here>)

As you might guess, operations on booleans include and, or, and not.

Also, Racket has symbols. Symbols are something like a cross between strings and enums. symbols can be written like this:

They start with a single quote, and then a sequence of alphanumeric characters. For now, the only operator we’ll use on symbols is equality comparison, with symbol=? .

We can also define functions. Here’s a simple function that adds two numbers together:

  ; add-nums : number? number? -> number?
  (define (add-nums a b)
    (+ a b))

Try running this program. Does it work? Who knows? We can’t tell, because we didn’t test it.

In order to build a test case, you’ll need to know how to call the function that you defined. It turns out that you call your functions in exactly the same way that you call the built-in functions: an open paren, the name of the function that you’re calling, zero or more arguments separated by spaces, and finally a closing paren.

Try calling the add-nums function, then add a test case for it and run it, making sure that the test case passes, and that the body of the function is no longer red.

5 Exercises

Okay, on to some exercises from htdp (available online at http://www.htdp.org/2003-09-26/Book/):

5.1 Simple data

Make sure to have at least one test case for every function that you write.

When you’re done with exercise 2.3.2, show it to me for credit.

5.2 Mixed groupings of simple data

Avoid section six!