Index: DrScheme Basics, Step-by-step Evaluation, Design Recipe, Other Basics
The main goals of this lab are to ensure that you can
Outside of lab, don't forget to get a homework partner, if you haven't already. Partners are encouraged to attend the same lab section.
This has nothing to do with the registrar. This will change your programming environment slightly to access course software more easily.
You won't need to do this ever again. |
This will show you a few UNIX basics you'll need to know, and prepare you for using DrScheme.
|
That's almost all you will need to know about the UNIX operating system for this course. But, if you would like to learn more, you can take a UNIX short course offered by Information Technology. Also, COMP 212's labs will describe more UNIX basics.
|
The DrScheme window is divided into two halves. The lower half, or interaction window, is the Scheme "calculator". The top half, or definition window is nothing but a text editor which is smart about indenting Scheme, and such. The execute button sends the contents of the definition window down to the interaction window, where they are actually evaluated.
For home use, you can download DrScheme.
|
DrScheme has lots of other features, including a complete manual. We'll explore more of DrScheme in later labs, and we encourage you to explore, but there's no need to learn all its features. Read the DrScheme Tips and Traps page for helpful information on common mistakes, error messages, etc.
While DrScheme evaluates our Scheme programs for us, it is also important for us to understand the process of evaluation. The details of evaluation will be covered in class. Here in lab, we want to explore two useful tools to help us:
|
"Hand-evaluation" is just you doing the same thing as DrScheme's stepper. It is useful to convince yourself that you know what is supposed to happen, independently of having DrScheme help you.
|
We will discuss these in class this coming week, but here's a preview. Programming methodology is a very important component of this course, and you will be required to follow these ideas, so the earlier you get into the habit of using them, the better.
When writing programs, there are lots of things we need to think about. It helps if we have some guidelines to follow that remind us to do these things in the proper order. While following some strict rules can seem annoying at first, in the end it will save you lots of errors and grief. These guidelines will be our design recipes.
Working with unstructured data, like the integers that we've seen, is relatively simple:
Write the function's contract, purpose, and header.
The contract specifies the function name and what kind of values the function will use as input and output. The purpose is a short statement describing what (not how) the function will calculate. The header is the part of the function definition specifying the function and parameter names.
Type these in the definition window. Put the contract and purpose in comments. E.g.,
; owe : nonneg-num -> nonneg-num ; Purpose: owe returns how much money you owe for the given number of ; pizza slices. (define (owe slices) ...)or
#| owe : nonneg-num -> nonneg-num Purpose: owe returns how much money you owe for the given number of pizza slices. |# (define (owe slices) ...)
We won't use DrScheme to verify that our contracts are correct, although that is a very useful thing to do. Look for that in COMP 212.
Make some examples of what the function should do. You need to make sure you understand what the function is supposed to do before you define it. When applicable, use some of the example data.
Put these in comments also, e.g.,
#| (owe 0) 0 (owe 10) 15 |#or, if you want it to print out:
"owes examples:" (owe 0) 0 [etc...]Helpful hint: You can actually type
(= (owe 0) 0) (= (owe 10) 15)if you like. We'll explain the output after explaining
=
in class.
Write the function body.
For programs on "unstructured" data like numbers, this is very straightforward, because we are typically given an equation, e.g.,
(define (owe slices) (* (/ 12 8) slices))For sets of intervals or other conditional functions, there should be exactly one condition clause per option.
Test the function. Make sure the previous examples really work.
If you wrote the tests as suggested above, you can test them by uncommenting them, and executing the program again. You'll see the results of the tests together with the expected answers. If your program doesn't work, either fix it now or put that in comments too, to remind yourself to fix it later, and to let your grader/boss/customer/whomever know also.
Later, we will have additional design recipes for more complicated data and program styles.
Follow these steps to define a function calculating the area of a circle, as discussed in class. |
These things probably won't be covered in lab. Make sure you're familiar with
Newsgroups are electronic bulletin boards where everybody can post and read articles on certain topics. There is a newsgroup specifically for this course, rice.owlnews.comp210. You should read the newsgroup every day, as helpful hints and clarifications are posted there regularly. Also, if you have a question relating to the course, post it to the newsgroup. Similarly if you have an answer for somebody else's question!
In newsgroups, the idea is that once you've read a message, you probably don't ever want to see it again. So your newsreader "marks" an article as read, and ext time you read news it only presents you with unmarked articles. (You also have options such as unmarking read articles or looking at all articles.) Most newsgroup-reading programs also group articles by thread, i.e., grouping articles with any replies. A common problem is to "lose" a message by reading it and then not marking it as unread. There are many different news-reading programs you can choose from. Two leading contenders are Netscape and Pine, each of which makes reading news analagous to their way of reading email. ( Trouble accessing newsgroup?)
Always "log out" from your UNIX account when you are done and leaving. Otherwise, someone can use your account, e.g., to copy or delete your assignments. One way is to type logout in the "console window" which is labeled. You do not need to exit any other programs first, but be sure to save any important changes first.