Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Outside of lab, don't forget to get a homework partner, if you haven't already. If you're having trouble getting a partner, try using the sign up sheet. Partners are encouraged, but not required, to attend the same lab section.

...

DrScheme Basics

Make #Open a terminal.
#Make a new folder (directory (folder) , for today's work.

HTML
<table border="1" bgcolor="#efefdf" align="center">
HTML
<tr>
HTML
<td>

On the Owlnet PCs, your "My Documents" folder is the same location as your "U:" drive, which is the same location as your Unix login directory.

We will refer to your U: drive, as this is more closely related to how your computer in your room might be set up (ask the TAs, labbies, or your college's SCCs how to "map" your Unix account to your personal computer).

called Comp211, for this course. The command is for making a new folder on Linux is mkdir.

  1. Make a sub-folder in Comp211 called Labs.
  2. Make a sub-folder in Labs called Lab01.
  3. Make a folder in your U: drive called Comp211.
  4. Make a sub-folder in Comp211 called Labs.
  5. Make a sub-folder in Labs called Lab01.
  6. Save all your Lab01 work to this folder.

For submitting homeworks, see the SVN Turnin page.

HTML
</td>
HTML
</tr>
HTML
</table>

Start DrScheme

HTML
<table border="1" bgcolor="#efefdf" align="center">
HTML
<tr>
HTML
<td>
  1. Start the DrScheme program., which can be found in the Start menuFor submitting homeworks, see the Owlspace page for Comp 211.
    #Start DrScheme by typing the command drscheme.
  2. If this is the first time you've run ! DrScheme, it will ask you your preferred language, and the Scheme language level; the latter should be "Beginning Student ". This level makes DrScheme catch more errors for you: namely, errors which are technically legal Scheme, but are probably not what you really want early in the course.
    HTML
    </td>
    HTML
    </tr>
    HTML</table>with List Abbreviations". This language level provides the expected set of primitive operations and enables DrScheme to reject "legal" Scheme constructions that are
    not part of our introductory dialect.

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 just 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.We suggest that you download DrScheme to your home computer/laptop. Versions are available for all major platforms.

For our running example, we'll look at a common college problem: how to divide the cost of a pizza. For simplicity, we'll assume that a pizza costs $12 and is cut into 8 slices.

Simple example of using

...

DrScheme

...

HTML
<table border="1" bgcolor="#efefdf" align="center">
HTML
<tr>

...

  1. Type (or cut/paste) the following following blocks of code into the definition window, including:
    Code Block
    (+ 2 7)
    
    (* (+ 2 7) 3)
    
    ;; owe: nat -> num
    ;; Returns how much money you owe for eating the given number of
    ;; slices of pizza.
    ;;
    (define (owe slices)
       (* (/ 12 8) slices))
             

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

  1. We included comments before each function definition, explaining what it is supposed to do. DrScheme ignores the comments, but you, your grader, your boss, etc., can read them. Soon, we'll provide more guidance on what to say in your comments.
    code {{
    ; One form of comments is anything following a semicolon
    ; up to the end of the line.
    ;; However, you'll often see two semicolons starting a comment. #| Another form of comments is anything between these two matching markers. |#

#|
Another form of comments is anything between these
two matching markers.

#
}}

You can also go to the Special menu, choose Insert comment box. You are welcome to do this, but one caveat: if DrScheme saves a file which includes a fancy comment box, the file will not be saved in plain-text format. (This is only an issue if you want to open or print the file with a different program later.)

  1. Edit your definitions or comments some. You can use the mouse, the arrow keys, backspace, and standard keyboard shortcuts to move the cursor around. Also, the PC, Mac, and Unix versions of DrScheme each use their respective standard keyboard shortcuts. (You can look in the Edit menu under Keybindings for the complete list.)
  2. Load the definitions into the interaction window by clicking on the Run button. If DrScheme detects any syntactic errors, it will give you an error message in the interactions window and highlight the error in the definitions window.
  3. Use those definitions by typing in the interaction window some Scheme expressions using those definitions. E.g.,
    code {{
    (owe 5)

(owe

...

7)

...


}}

  1. Save your work in your U:\comp211Comp211\Labs\Lab00\ Lab01 directory. Be sure to use a filename that has a ".ss" extension. You don't need to turn in your lab work. In fact, you don't have to save it, but we recommend it so that you can look at it again.
  2. Finally, intentionally introduce an error ( or, what you think will be an error), press Run, and see what error message is given. We'll go around the room to see what different error messages people get. Do the error messages tend to make sense?

...

...

</td>
HTML
</tr>
HTML
</table>

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.

...

  • !DrScheme's stepping tool that illustrates evaluation.
  • A technique for the programmer to illustrate and check evaluation "by hand".

Using !DrScheme's stepper

HTML
<table border="1" bgcolor="#efefdf" align="center">
HTML
<tr>

...

  • and check evaluation "by hand".

Using DrScheme's stepper

  1. Place an example use or two of your functions in the definitions window, after the appropriate definitions. For example,
    Code Block {{
    (owe 10)
    }}
  2. Click on the Step button. This brings up a new stepper windows which will show how DrScheme calculates the answer.
  3. Use the stepper's button to look through the evaluation. At each step, it shows what part of the code needs to be evaluated next, and what the result is.
HTML
</td>
HTML
</tr>

...

  1. result is.

Illustrating hand-evaluation

HTML
<table border="1" bgcolor="#efefdf" align="center">
HTML
<tr>

...

...

<td>

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

  1. Hand-evaluate a few example expressions, and type in each of the small steps you would make to calculate the result. Type these in the definitions window after your definitions. For example,
    code {{
    ;; Hand-evaluation:

(owe

...

10)

...

(*

...

(/

...

12

...

8)

...

10)

...

(*

...

3/2

...

10)

...

15
}}
This is just high school algebra, successively simplfying expressions, until you reach a final, simple value.

    • What do you hope to see, when you Run all these expressions? What would you see if there were a mistake?
    • While you are doing this, it is often 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.
  1. Verify your steps by clicking Run.
  2. Once you've used this to verify your steps, put the steps in comments, rather than deleting them. (Later, you might change the code, and you want to re-use these as test cases.)
    HTML
    </td>
    HTML
    </tr>
    HTML</table>

Design Recipe

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.

...

  1. 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, as in the following examples:
    Code Block {{
    ;; owe : nat -> num num
    ;; Returns how much money you owe for eating the given 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.

  1. 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. We recommend the following form for these examples:
    Code Block {{{
    ;; Examples:
    ;; (owe 0) => 0 0
    ;; (owe 10) => 15 15
    }}
    The first line provides an explanation of the following, making it more readable. (We haven't introduced symbols yet officially -- we will see them in class soon.) The next two lines each give an example, asking DrScheme to compare (with the numeric equality function =) the actual result with the expected result. You should pick enough examples to test the function adequately. We'll say more about that later, but this should include any interesting inputs like zero.
  2. Write the function body. Soon, we will have lots to say about this step. For now, for programs on "unstructured" data, this is very straightforward, because we are typically given an equation like …
    Code Block {{
    (define (owe slices)
    (* (/ 12 8) slices))
    }}
    For sets of intervals or other conditional functions, there should be exactly one condition clause per option.
  3. Test the function. i.e., make sure the previous examples really work. If you wrote the examples as suggested above, you can use them to test the function. Add a test section after your function definition, like this:
    Code Block
          "Testing owe:"
          (equal? (owe 0) 0))
          (equal? (owe 10) 15))
       
    All of these tests should return true , assuming that the tests themselves are correct. 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. The better your test, the more errors you'll catch sooner and the less time it will take to write a correct function.

...