Lab 1, CSC430, Winter 2015
1 Starting up Dr  Racket, registering for a handin account
2 Using Dr  Racket
3 Elements of Racket
4 Exercises
4.1 Simple data
4.2 Mixed groupings of simple data
6.1.1.8

Lab 1, CSC430, Winter 2015

1 Starting up DrRacket, registering for a handin account

Start up DrRacket; it should be installed on the Lab machines.

After starting up, you’ll need to choose a language. Choose "The Racket Language".

Next you’ll need to install three things: the plai-typed language, the match extensions to the plai-typed language, and the handin plugin. Follow the instructions on the course syllabus to install it.

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. Use "0".

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.

2 Using DrRacket

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

#lang plai-typed
 
(+ 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?

3 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.

Wait, what? What the heck are those? Figure out what those are.

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:

(define (add-nums [a : number] [b : number])
  (+ a b))

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

One way to see this is to enable "Syntactic Test Suite Coverage" in the "Language Details" section of the Language|Choose Language... menu item. Try turning this on.

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. Check that the syntactic test suite coverage tool now shows the body of the add-nums function as covered.

4 Exercises

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

4.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 feedback.

4.2 Mixed groupings of simple data

When you’re done with these, demo them to me as well. This is how you receive credit for the lab.

As a means of backup, you must also submit the lab using the handin button. This ensures that we have some record of your code, if I happen to lose it.