Comp 210 Lab 1: Getting Started: DrScheme, Design Recipe

Index: Register, DrScheme, Design Recipe, Hand-evaluation, Other basics, Logging out

The main goals of this lab are to ensure that you can


Registering for Comp 210

You should have an Owlnet account already. Freshmen usually receive accounts during O-week. If you do not already have an account, go to the information desk in Mudd.

To do: First, each student needs to "register" for this course. This has nothing to do with university course registration. This will tweak your computing environment to simplify access to the course tools. In one of the xterm windows, type register comp210 (followed by the Return key). Answer y (yes) to any questions it asks.

To do: For most of these changes to have effect, log out and then log in again. The most visible change is that there is now a small menu for Comp 210 on your screen.

If you have a problem registering, you probably have changed your windowing environment substantially from the Owlnet default. Talk to a labby or Mudd consultant after lab.

For the curious... registering is not necessary, but should be done unless you are very familiar with UNIX. This command alters several files, including your .cshrc and .twmrc, adding things to your PATH and your windows setup.


DrScheme

To do: Start DrScheme by either

Either of these should work after you have registered for the course. If you had problems registering, start DrScheme by typing ~/comp210/bin/drscheme in an xterm window.

To do: For this first time only, from the Language menu, select Configure Language. From the menu that gives you, select Beginner. When set at Beginner, DrScheme can catch more errors for you: namely, errors which are technically legal Scheme, but are probably not what you really want early in the course.

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 merely a text editor (which is smart about indenting Scheme, and such).

Simple examples

To do: Enter the two lecture examples of definitions:

     (define (area r)
        (* (* r r) pi))

     (define (wage h)
        (* h 5.65))
Remember, definitions go in the top half.

DrScheme helps you with the indentation if you use the Return key in appropriate places. Observe that DrScheme "bouces" the cursor to visually match the closing parenthesis with the corresponding opening parenthesis.

To do: Now we want to use those definitions. To do so, we first need to "load" those definitions into the calculator part of DrScheme by clicking on the "Execute" button. Now, in the bottom half of the window, type in some Scheme expressions, including some using area and wage.

Really simple editing

To do: We would like to use more mnemonic placeholder names than r and h. Wouldn't radius and hours be better? Edit the above definitions to use these (or similar names). Then reload ("Execute") your changed definitions and see if they still work as before.

To edit, you can use the mouse, arrow keys, and backspace as you would expect. There are also key strokes that you can learn, such as Control-p, Control-n, Control-b, Control-f, Control-a, and Control-e for moving the cursor around. Some people prefer using the mouse, some people using the keyboard.


Design Recipe

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, an first, seem annoying, in the end it will save you lots of errors and grief.

These guidelines will be our "Design Recipe". For now, our recipe consists of the following four steps:

  1. Write the function's contract and header.

    The contract specifies what kind of values the function will use as input and output, e.g.,

         area : number -> number
    
         wage : number -> number
         
    Type these in DrScheme (in the definition window, where we'll put the function definitions) in comments, e.g.,
         ;; area : number -> number
         
    or
         #|
         wage : number -> number
         |#
         
    These will be ignored by the "little man" inside the computer, and are only used by the humans reading your code (you, your grader, your boss, ...). This is just notation listing the function name, the kind of input(s) the function expects, and the kind of output it produces.

    When it is not obvious from the function name, you should also put in comments a more detailed description of what the function computes.

    The header is the part of the function definition specifying the function name and contract, e.g.,

         (define (area radius) ...)
         (define (wage hours) ...)
         

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

    Put these in comments also, e.g.,

         #|
         (wage 0) = 0
         (wage 10) = 16.50
         |#
         

  3. Write the function body.

    E.g.,

         (define (wage hours)
            (* hours 5.65))
         

    For now, this should be very straightforward. As we learn more about programming, we will need more guidelines.

  4. Test the function. Make sure the previous examples really work.

    If it doesn't work, put that in comments too, to remind yourself to fix it later, and to let your grader/boss/customer/... know also.

To do: Follow these rules to define some functions, e.g., f2c, which converts fahrenheit to celsius.


Hand-evaluation

To do: Hand-evaluate some example expressions. Type in each of the small steps that the "little man" or you would make to calculate the result, e.g.,

     (area 10)
     = (* (* 10 10) pi)
     = (* 100 pi)
     = (* 100 3.1415926535)
     = 314.15926535
Put these with your code too. Separating each of the steps with an equal sign is a neat little trick to make things look nice. You can verify your steps clicking "Execute" -- you should see the same answer multiple times, once for each step. (Once you've used this to verify your steps, put it in comments, rather than deleting it.)

While you are doing this, it is helpful to copy the previous step, and edit this copy for the current step. This can save you some typing, and it helps eliminate mistakes. You'll want the "Copy" and "Paste" features in the "Edit" menu. Or, note that there are keyboard equivalents listed in this menu.

Try some other examples, possibly with some other simple definitions.


Other basics

These things probably won't be covered in lab. Make sure you're familiar with email, the course Web pages, and the course newsgroup.

Email

We assume that you already know how to use email.

Netscape

(If you are already familiar with Netscape, play around with DrScheme some more, or browse the Comp 210 pages.)

By now, anyone not living in a cave at least knows what the Web is. Netscape (or, more properly, Netscape Navigator) is a window-based program for exploring the Web.

To do: Use Netscape to look at the courses' information.

Be sure to read the information on the course pages! Most of the couse information, including assignmnets, will be availably only online.

If you find a document of particular interest, you can remember it by creating a "bookmark" for it: pull down your Bookmarks menu, and select Add Bookmark. Any time you want to revisit that page in the future, you can just select it from the Bookmark menu (where it is now listed).

To exit Netscape, select Exit from the File menu.

News

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 next 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.)

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. The following is a brief introduction to Netscape's news. More help is available from Owlnet documents or your fellow students.

News with Netscape

To do: From the course home page, select the link "The Newsgroup". This opens a separate Netscape window. You will see a list of articles/threads in current newsgroup, and an area for the body of current article. Articles are organized into threads -- any reply to an article is in the same thread.

There will be at least one recent message for the course. Be sure to read any of these (e.g., clicking on a message's title, or using the Next button to go to the next message). Most of the messages you will see pertain to previous semesters -- don't bother reading them.

To post your own message to a newsgroup, you must be in that newsgroup. Then use either the New Msg or Reply button, as appropriate. You'll be put inside an editor to compose and send the message.

Play around. If you're like me, you'll want to change some of the default behaviors.

Note that under the File menu of Netscape's News window, Close just closes the News window only, while Exit actually means exiting all Netscape windows.


Logging out

Always "log out" 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.