<?php require_once "fs_inner_context.inc"; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">

<title><?php echo $HTML_TITLE; ?></title>

</head>

<?php echo html_bgcolor_body($BG_COLOR); ?>

<!-- Standard hierarchical header structure -->

<?php echo $CS_HEADER_HTML; ?>

<?php echo html_linked_text("<em>Courses</em>", $CS_COURSES_ROOT_URL); ?>

<?php echo $HTML_HEADER; ?>

<hr><hr>

<strong>[23 Sep 2003] I am updating this assignment from 2002 to 2003. Details may change. [MOD]</strong>

<p>Assignment #0 is due at 11:59 PM on Friday, 3 October 2003. Submit
your work according to the
<?php echo html_linked_text("general instructions", ".."); ?>.</p>

<p>This assignment is designed to exercise you in the annoying
logistical details that you need to handle while programming. There is
no interesting programming problem for you to solve. It is very
important that you are not distracted by too many logistical details
in the subsequent assignments, which will present you with interesting
conceptual problems to solve. So, try to shake out your methods for
working on this trivial assignment.</p>

<p>I've described much of what you need to do for Assignment #0 in
highly annoying detail. I will never do that again in this
class. After this assignment, I will describe your work clearly enough
that you can figure out what you need to do, possibly after asking
some questions. In order to succeed in the later work of the course,
you <em>must</em> use Assignment #0 to become <em>fluent</em> in the
basic operations of programming and exploring with
<em>DrScheme</em>. If you fumble around a lot about which buttons to
push when, you will not be able to concentrate on the interesting
problem-solving content of the real assignments.</p>

<p>You only hand in a small part of the work in this assignment. But
do it all.</p>

<p>These instructions describe how to perform assignment #0 on one of
the CS Department's <em>GNU/Linux</em> computers. You may use
<em>DrScheme</em> on another computer if you like (e.g. the CS
Department's <em>Macintosh</em> computers). In that case, it's a good
idea to make sure that you have the same version of <em>DrScheme</em>
(it was version 205 last time I checked). And you will have to figure
out any differences in the methods of working. In particular, you will
have to transfer your files to the CS Department's <em>Linux/Unix</em>
file system in order to hand them in. I will not have time to figure
out problems due to the use of different computers.</p>

<?php echo html_header($HTML_HEADER_LEVEL + 1,
                       "1. Start <em>DrScheme</em> and select your language"); ?>

<ol>

<li>Log in to a Computer Science Department <em>Linux</em>
computer. Open an interactive terminal/shell window. Use the
"<code>mkdir</code>" command to create a directory in which to work on
CMSC 16100 homework, with a subdirectory named "<code>Asst0</code>"
for this assignment. Use the "<code>cd</code>" command to move into
that directory, and the "<code>ls</code>" command to notice that
there's nothing in it yet. If you don't know how to do all this stuff
in <em>Linux</em>, get help from a friend, a TA, or a consultant in
the CS instructional computing labs in Regenstein.<br><br></li>

<li>Start <em>DrScheme</em> by typing "<code>drscheme &</code>" to
your interactive terminal/shell window (the "<code>&</code>" causes
<em>DrScheme</em> to run in the background, allowing you to type
further commands if you need to).<br><br></li>

<li>As <em>DrScheme</em> starts, accept the default choices of
"English" and "Beginning Student".<br><br></li>

<li>Select "About DrScheme" from the "Help" menu, and verify that you
are using version 205. Take the "Tour" if you like, but it is designed
more for beginning instructors than for students.<br><br></li>

<li>Select "Choose Languages" from the "Language" menu. Notice that
<em>DrScheme</em> starts up with the "Beginning Student"
language. Upgrade yourself to "Beginning Student with List
Abbreviations".<br><br>

Select the "Show Details" button, and notice that there are
a number of choices having to do with input and output "syntax" (that
is, notation).<br><br>

Don't worry about the meaning of the language choices now, but
remember their presence for later consideration. They affect

<ul>

<li>which features of <em>Scheme</em> you are able to use,</li>

<li>whether capitalization affects the meaning of expressions that you
enter to <em>DrScheme</em>, and</li>

<li>how <em>DrScheme</em> displays <em>Scheme</em> values that you
compute.</li>

</ul>

When you discuss and compare work with other <em>DrScheme</em> users,
make sure you notice whether you are using the same language
choices.

</li>

</ol>

<?php echo html_header($HTML_HEADER_LEVEL + 1,
                       "2. Evaluate arithmetic expressions in the interaction window"); ?>

<ol>

<li>The <em>DrScheme</em> user interface shows two windows in which
you may type. The top one is called the "definitions window", and the
bottom one is called the "interaction window". Point to the bar
between the windows until you get a diamond-shaped pointer, press the
left mouse button, and move the bar up to make the interaction window
bigger.<br><br>

When you type in these windows, the presence or absence of space
between two typed characters may make a big difference, but the amount
of space makes no difference, even when it takes you to a new line of
text. In the jargon of <em>Scheme</em>, and many other programming
languages, a sequence of one or more blank spaces, tabs, and/or line
breaks is called "whitespace".<br><br>

Type "<code>(+ 2 3)</code>" in the interactions window, and hit the
enter key to evaluate that expression. You should see the result
"<code>5</code>", but also a yellow-highlighted warning:
"<code>WARNING: Interactions window is out of sync with the
definitions window. Click Execute.</code>" In this case, it really
means that the interactions window has not incorporated the change
from <em>Beginning Student</em> to <em>Beginning Student with List
Abbreviations</em>.<br><br>

Select the "Execute" button. Notice that the interactions window now
confirms your use of <em>DrScheme</em> version 205 and the
<em>Beginning Student with List Abbreviations</em> language. But you
appear to have lost your expression adding 2 and 3. Not so. Type
"<code><em>Escape</em> p</code>" to recover your expression, and
"<code><em>Enter</em></code>" to evaluate and display the result
"<code>5</code>" without the warning.<br><br>
</li>

<li>Evaluate lots of variations on "<code>(+ 2 3)</code>", such
as<br><br>

<ul>

<li><code>(+2 3)</code></li>
<li><code>(2 + 3)</code></li>
<li><code>((+ 2 3))</code></li>
<li><code>( + 2 3 )</code></li>
<li><code>(* (+ 2 3) (/ 42 7))</code></li>
<li><code>(*(+ 2 3)(/ 42 7))</code><br><br></li>

</ul>

to get an idea of the effects of parentheses, white space, order of
tokens. Evaluation of some of these expressions is erroneous. Avoid
retyping everything by using "<code>Escape p</code>" to recover old
expressions and then editing them.</li>

</ol>

<?php echo html_header($HTML_HEADER_LEVEL + 1, "3. Evaluate different
types of expressions in the interaction window"); ?>

<ol>

<li>Evaluate<br><br>

<ul>

<li><code>(append (list "a" true 3) (list false "efg" 'hi))</code></li>
<li><code>(length (append (list "a" true 3) (list false "efg" 'hi)))</code></li>
<li><code>(list)</code></li>
<li><code>(append (list 1 2 3 4) empty)</code></li>
<li><code>(append empty (list 1 2 3 4))</code></li>
<li><code>(length (list (list 1 2 3 4) empty (list 5)))</code><br><br></li>

</ul>

Think about the nature of lists in <em>Scheme</em> as suggested by
these examples. (If you have seen another form of <em>LISP</em> or
<em>Scheme</em> in the past, you will notice that <em>DrScheme</em>'s
presentation of list values is a bit different from the one you saw
before. But the values themselves are the same.)

<br><br></li>

<li>Think about the variety of types of <em>Scheme</em> values in the
examples above. <em>Number</em>s, <em>boolean</em>s, <em>list</em>s,
<em>symbol</em>s, and <em>string</em>s will be important to us as the
quarter progresses. Evaluate "<code>(list?  (list 1 2 3))</code>",
"<code>(list? empty)</code>", and "<code>(list?  "(1 2 3)")</code>" to
get an idea what lists are (and what they are not).<br><br>

Try lots of other examples, using the operations
"<code>number?</code>", "<code>boolean?</code>",
"<code>symbol?</code>", "<code>string?</code>", and
"<code>char?</code>". Figure out the types of lots of values such as
"<code>123</code>", "<code>'123</code>", "<code>(list "1" "2"
"3")</code>", "<code>abc</code>", "<code>'abc</code>", "<code>(list
"a" "b" "c")</code>". Most of these make a lot of logical sense after
you assimilate them, but there are some subtle quirks, such as the
different effects of single- or double-quoting "<code>123</code>"
vs. "<code>abc</code>". It's not important to understand the whole
mess right now---just get a sense of the scope of the problem, and
we'll treat each type more carefully later.</li>

</ol>

<?php echo html_header($HTML_HEADER_LEVEL + 1, "4. Define a new
    function in the definitions window"); ?>

<ol>

<li>Enter the following text in the <em>definitions</em> window (the
top window):

<blockquote><pre><code>
; rotate-list-left is a function that rotates the elements
; of a list to the left, moving the first element to the
; last position.

(define (rotate-list-left listin)
  (reverse (cons (first listin) (reverse (rest listin)))))
</code></pre></blockquote>

This is a tiny <em>Scheme</em> program, defining the function
<code>rotate-list-left</code>. Select the "Check Syntax" button. If
you typed it all in correctly, you will see a nicely color-coded
display of the text. I don't recommend learning the meanings of the
colors (I still haven't done so), but I think their presence makes the
program easier to read.<br><br>

If you mistyped something, you will probably see an error message
in a small window above the definitions window, and a portion of the
program will be highlighted in pink. <em>DrScheme</em> finds it likely
that you mistyped something in the pink region. If you're lucky, the
region is small. If you're unlucky, it contains the whole program.<br><br>

Even if you typed everything correctly on your first try (or if you
were clever enough to cut and paste instead of typing), introduce some
errors deliberately, notice the message and highlighting, and then
correct your errors. Omit parentheses, and add extra ones. Misspell
one of the instances of "<code>listin</code>", perhaps as
"<code>litsin</code>". Each time you change the program, select "Check
Syntax" again.<br><br>

With a syntactically correct program, click next to a parenthesis, to
place the cursor there. Notice the grey highlighting. Place the
pointer over the first instance of the symbol <code>listin</code> and
notice the blue arrows. Think about what they might be telling
you. This is some of the really nice stuff in <em>DrScheme</em>, and
there's a bit more of it to discover.<br><br>

If you are <em>really</em> unlucky, there will be no error message,
but the program will define a different function from the one that I
intended.<br><br></li>

<li>With a seemingly correct program (one that passes "Check Syntax" with
no error message), evaluate "<code>(rotate-list-left (list 1 2 3
4))</code> in the <em>interaction</em> window. Oops! We forgot to
select the "Execute" button. <em>DrScheme</em> warns us that the two
windows are out of sync, and tells us that
"<code>rotate-list-left</code>" is an "undefined identifier". Select
the "Execute" button. The nice coloring disappears, which annoys me a
lot, so I select "Check Syntax" again immediately. Your expression to
evaluate also disappears from the interaction window, but you can get
it back with "<code>Escape p</code>". When you finally see it, the
result of this example should give you the basic idea of what
<code>rotate-list-left</code> is intended to do.<br><br>

Try to think of some subtle points about the behavior of
<code>rotate-list-left</code>, and evaluate other expressions to
illuminate those subtle points. If you must do something on your own
already, figure out how to define <code>rotate-list-right</code> in
the same style. It's only slightly more complicated<br><br></li>

<li>Add a comment (lines starting with "<code>;</code>") to the top of
the definitions window with your name displayed prominently, as
specified in the
<?php echo html_linked_text("general instructions", ".."); ?>.<br><br></li>

<li>Select the "Save" button. A new window will pop up, with a text
entry field at the bottom, with some stuff already typed
in. <em>Add</em> "<code>/rotate-list-left.scm</code>" to the end of
that stuff, and select the "OK" button. Back in your <em>Linux</em>
terminal/shell window, type "<code>ls</code>", and notice the new file
named "<code>rotate-list-left.scm</code>". That file contains only the
contents of the definitions window. Get in the habit of selecting
"Save" after every change to the definitions. You only have to enter a
file name the first time.</li>

</ol>

<?php echo html_header($HTML_HEADER_LEVEL + 1,
                      "5. Create and execute a test suite"); ?>

<ol>

<li>From the "File" menu, select "New Test Suite". A new window will
pop up. Select the "New Test" button. In the "Call" region, enter
"<code>(rotate-list-left (list 1))</code>", and in the "Expected"
window enter "<code>(list 1)</code>". Select the "Execute" button on
the <em>test suite</em> window (not the one on the definitions
window). "<code>(list 1)</code>" will appear in the "Actual" region,
and a big green check mark to indicate that the program passed the
test.<br><br></li>

<li>Add the following additional tests, using the "New Test" button
each time:<br><br>

<ul>

<li><code>(rotate-list-left (list 1 2))</code> and
<code>(list 2 1)</code><br><br></li>

<li><code>(rotate-list-left (list 1 2 3 ))</code> and
<code>(list 2 3 1)</code><br><br></li>

<li><code>(rotate-list-left (list (list 1 2 3)))</code> and
<code>(list (list 1 2 3))</code><br><br></li>

<li><code>(rotate-list-left (list (list 1 2 3) (list 4 5 6) (list 7 8 9)))</code>
and <code>(list (list 4 5 6) (list 7 8 9) (list 1 2 3))</code><br><br></li>

</ul>

By this point, you'd better figure out how to cut and paste, instead
of retyping all of these expressions. You also need to figure out how
to expand the test suite window, so you can see the whole list of 5
test cases. Select the "Execute" button to see our program pass the
tests. Think about why I chose those particular tests.<br><br></li>

<li>I left out one very important test. Add it:<br><br>

<ul>

<li><code>(rotate-list-left empty)</code> and
<code>empty</code><br><br></li>

</ul>

Notice that my program fails this test, not by producing a wrong
result, but by failing to produce any result. Think about why
<code>empty</code> is arguably the right result, and why my program
doesn't get it.<br><br>

To see how <em>DrScheme</em> displays more conventional failures of
tests with a red "X", change one of the "Expected" entries, but fix it
again after you've seen the result.<br><br>

In your further work in the class, every function that you define in a
program must be tested in a test suite. Most of the time, your
programs will fail their tests, and you will work to correct them. We
will discuss how to craft good test suites later.<br><br>

Test suites are another really nice feature of <em>DrScheme</em>. But,
they have some shortcomings. For example, if one test case fails to
produce any result (such as <code>(rotate-list-left empty)</code>
above), no further test cases are executed. That's why I saved the
<code>empty</code> test for last. There is also no way to incorporate
tests that are <em>intended</em> to fail in this way, even though that
is sometimes the desired result. Later on, we may switch to a more
carefully crafted testing procedure that doesn't look as nice.<br><br>

<strong>Warning: <em>DrScheme</em> tests the last <em>saved</em>
version of your program. If you have changed the program in your
definitions window, but did not yet save it, you will test the
previous version. I think this is the wrong behavior, and a later
version of <em>DrScheme</em> will correct it. For now, remember to
save before executing a test suite.</strong><br><br>

<li>Use the "File" menu on the test suite window to save your test
suite with the name "<code>rotate-list-left.tst.scm</code>".</li>

</ol>

<?php echo html_header($HTML_HEADER_LEVEL + 1,
                       "6. Check out the <em>Scheme</em>
    documentation"); ?>

<ol>

<li>Select "Help Desk on the "Help" menu. Find the <em>Revised^5
Report on the Algorithmic Language Scheme</em> (you have to hunt down
a few levels in the help materials). This is the definitive reference
for the <em>Scheme</em> programming language, but not for the
<em>DrScheme</em> interface. It is rather hard to read. But in order
to program effectively, you must be able to dig precise information
out of manuals like this, even though you may not understand all of
the surrounding information.<br><br></li>

<li>Find the list of trigonometric functions in standard
<em>Scheme</em>.</li>

</ol>

<?php echo html_header($HTML_HEADER_LEVEL + 1,
                       "7. Hand in your definitions and test suite,
    and notice how to continue work"); ?>

<p>Hand in your definitions and test suite according to the
<?php echo html_linked_text("general instructions", ".."); ?>.
In this assignment, you just type

<blockquote><pre><code>
~odonnell/Teaching/Utilities/handin 0 rotate-list-left.scm rotate-list-left.tst.scm
</code></pre></blockquote>

To avoid typing the path prefix
"<code>~odonnell/Teaching/Utilities/</code>", see the
<?php echo html_linked_text("section on <code>PATH</code>", "..#PATH") . " "; ?>
in the
<?php echo html_linked_text("general instructions", ".."); ?>.
This is a good time to read about
<?php echo html_linked_text("the <code>handin</code> command", "..#handin"); ?>.</p>

<?php echo html_footer("index", 0, 1); ?>
<!-- hhmts start -->
Last modified: Sun Sep 28 22:50:52 CDT 2003
<!-- hhmts end -->

</body>

</html>
