%% -*- LaTeX -*-

\chapter{Overview}
\label{overview}

The 6.001 lab (room 34-501) is shared with 6.004; the left half of the
room (as you go in the door) has computers and oscilloscopes for
6.004, and the right half has several dozen Chipmunk computers for
6.001.  The printers are on your left as you enter the room.

The 6.001 Chipmunks are divided into four groups.  Each group shares a
printer and a large disk-drive, which holds the Scheme software and
the original copies of problem sets.  Your own Scheme programs and
your changes to the problem set originals are stored on removable
floppy disks.  Included with this set of notes were two floppy disks
for use in 6.001---one for storing your work and one to use as backup.
Always remember to bring your floppy disk when you come to the lab;
without it, there is no way to save the work you have done so you can
continue working on it the next time you visit the lab.

\section{Parts of the Chipmunk Universe}

Using a new computer system can be very confusing---there are many
different programs and parts of programs that relate in different
ways, and new users are often confused about which part of the system
they are dealing with.  This section provides a brief introduction of
the different parts of the Chipmunk universe: the Scheme interpreter,
the keyboard, the Edwin editor, the text and graphics display screens,
disks and files, text printers, and graphics printers.

\subsection{Scheme and Edwin}

The Scheme interpreter takes expressions and evaluates them according to
the rules of the Scheme language.  The programs you write, the simple
expressions you evaluate, all the examples in the 6.001 texbook are
Scheme expressions.  Later in the semester, we will see how the
evaluator works, at least in principle.

If all you ever did was type very simple Scheme expressions, then you
could use a system in which one typed characters directly at the
interpreter.  Indeed, the 6.001 textbook describes interactions with
the interpreter as if this were the case.  But, in reality, you want
to type complex expressions; you want to correct typing errors; you
want to store text in files; you want to format text so that it can be
read easily; and so on.  In the 6.001 system, these tasks are
accomplished with the aid of a program called a {\em text editor}.
So---you never (well, almost never) type at the Scheme interpreter
directly.  Instead, you use the editor to compose text, and, when you
are satisfied with the text you compose, you direct the editor
evaluate that text, i.e., to transmit it to the Scheme
interpreter.  Depending on the particular evaluation command you use,
you can direct the editor to transmit to Scheme a single line, a
single procedure definition, or a larger chunk of text.

What this means is that there are really two languages that you are
using in the lab, and two different kinds of commands you will be
typing at the Chipmunks.  There is Scheme itself, which performs
operations such as ``compute the factorial of 137'' or ``find the 10
element of this list.''  Then there are editor commands such as ``save
this text on the floppy disk'' or ``move the cursor down 5 lines.''

The editor used in 6.001, named Edwin, is a version of Emacs, the
editor used in Project Athena.  If you are familiar with Emacs, you
will find that essentially all of the basic Emacs editing commands
work on the Chipmunks.  If you do not know Emacs, you will need to
spend some time learning the basic commands.  In point of fact, most
of the editing you will need to do for 6.001 can be accomplished with
only a few simple editing commands, and you will soon become familiar
with these.  On the other hand, as the semester progresses, it will
become greatly worth your while to learn some of the more advanced
editing commands; these can save you enormous time at the keyboard.
Periodically during the semester, you should reread
chapter~\ref{edwin} of this manual and try out some useful commands
that you may not have previously noticed.

\subsection{Typing editor commands}

The Chipmunk keyboard contains a number of special keys in addition to
the usual alphanumeric ones.  Across the very top are two rows of keys,
most of them numbered.  These keys are also labeled.  For example, the
key numbered \kkey{2} is also labeled \key{extend}.

At the upper left of the keyboard is a key labeled \key{ctrl}.  This
is used like a shift key, i.e., you hold it down while pressing some
other key.  Thus, to type \ctrl\kkey{0}, you hold down \key{ctrl},
then press \kkey{0}, then release both keys.  Sometimes, \key{ctrl}
and \key{shift} are used together.  For example the command marked on
the keyboard as \key{write file} is typed as
\ctrl\shift\kkey{0} --- hold down both \key{ctrl} and \key{shift}, then
press \kkey{0}, then release all three keys.

Almost all the Edwin commands you will need to use in 6.001 are typed
as one of the labeled keys---either the key alone, the key shifted,
the key ctrl-ed, or the key ctrl-shifted.  All these possiblities are
labeled on keyboard.

One class of Edwin commands that are not on the special keys are
Edwin's {\em extended commands}.  To issue an extended command, you
press the \key{extend} key and then type the name of the command,
which Edwin will echo at the bottom of the screen.  For example, to
load the code for a 6.001 problem set you use the Edwin extended
command ``load problem set''.  Press \key{extend}, then type {\tt load
problem set} and press {\tt enter}.

For those of you who know Emacs, you will find that Edwin's editing
commands can also be typed in the usual Emacs way.  For instance, the
command to search for a given text string can be typed on the Chipmunk
as \kkey{5} or (as in ordinary Emacs) as \ctrl\key{S}.  You can use
either style command as you prefer.  Chapter~\ref{edwin} documents
both styles of Edwin commands.

\subsection{Buffers and files}

As described in chapter~\ref{edwin} below, the editor organizes
information in to chunks of text called {\em buffers}.  In general,
you will be working with many buffers at once, and Edwin includes
commands for switching between buffers, or even for viewing more than
one buffer on the screen at once by splitting the screen into separate
areas called {\em windows}.

When you tell Edwin to load a file from the disk, Edwin creates a
buffer that is associated with this file and loads the contents of the
file into a buffer so it can be edited.  If there is no file on the
disk with the name you specify, Edwin will create an initially empty
buffer associated to that file.

When you tell Edwin to save a buffer, Edwin will write the contents of
the buffer to a file on the disk.  Keep in mind that {\em no
information is written to the disk until you tell Edwin to save a
buffer}.  If you log out without saving your buffers, the contents of
these will be lost.  When you do log out, Edwin will notice if there
are buffers that you have modified but not saved, and ask you if you
want to save them before logging out.

\subsection{The Scheme interaction buffer, and evaluating Scheme commands}

In addition to the buffers associated to your files, there is a
special buffer called the {\em Scheme interaction buffer}.  Whenever
Scheme evaluates an expression, the result is placed in the Scheme
interaction buffer.

In an ordinary 6.001 session, you type short Scheme expressions in the
Scheme interaction buffer, tell Edwin to evaluate these expressions
(i.e., send them to the Scheme interpreter).  The result returned by
Scheme appears right below where you typed.  To evaluate an expression,
you press the \key{execute} key, located at the lower right of the
keyboard.  Pressing \key{execute} tells Scheme to evaluate the
expression immediately preceding the cursor.

Do not confuse \key{execute} with \key{enter}, which located at the
right of the keyboard, in the middle.  \key{enter} does not evaluate a
Scheme expression, Instead, it moves the cursor to the next line.  You
use \key{enter} in typing multi-lined expressions.  (On the other
hand, \key{enter} is used in issuing Edwin extended commands.)

You can evaluate Scheme expressions typed in any buffer, not just the
Scheme interaction buffer.  The only thing special about the
intecation buffer is that the values returned by Scheme are placed
here automatically.  If you wish, you can save the Scheme interaction
buffer in a file, edit it, or print it to obtain a transcript of your
session with Scheme.

In addition to the Scheme interaction buffer, you will ordinarily open
up another buffer in which you type procedure definitions, and save
this buffer in a file on your disk.  You will evaluate expressions
from this buffer, either one expression at a time, using
\key{execute}, or in larger chunks, such as groups of procedure
definitions or even evaluating the entire buffer at once.  (See
chapter~\ref{edwin}) for a description of Edwin's evluation commands.)
In each case, the result of the evlaution will appear in the Scheme
interaction buffer.


\subsection{Disks and files}

Your personal files are stored on a floppy disk.  In general, you use
Edwin commands to interact with files.  Edwin has commands for saving
the contents of a buffer in a file, and for reading a file from the
disk into a buffer, so it can be edited.

There is also a Scheme command called {\tt load} that takes a file
(which had better be a file of Scheme programs) and loads it directly
into the Scheme interpreter without going through Edwin at all.  You
would ordinarily use this command only for fully debugged code that
you don't want to see, just to load into Scheme.

\subsection{Text and graphics}

Each Chipmunk computer actually has two logically distinct screens
that share the same physical monitor---a text screen and a graphics
screen.  Normally, only text will appear on the monitor.  If you run a
Scheme program which draws pictures, you may need to press
\key{graphics} in order to see the image.  Pressing \key{graphics}
makes the graphics appear if it is not visible; pressing
\key{graphics} again, hides the text screen so that only the graphics
is showing.  The \key{alpha} key works similarly, showing text and
making the graphics invisible.

Text and graphics are also printed in different ways.  To print text,
you use an Edwin command that creates a listing on the central printer
that your Chipmunk shares with the others in its group.
Unfortunately, these printers do not print graphics.  To print a
picture, you need to run a Scheme command that saves the picture on
your disk as a ``picture file''.  Then you need to take your disk
to one of the special Chipmunks that has a graphics printer attached,
and issue another Scheme command that loads the graphics file and
prints you picture.  See section~\ref{printers} below for more
information.

\subsection{Summary}

Figure~\ref{universe} shows a summary of the parts of the system
described above, with indications of how information flows between the
various pieces.

\begin{figure}
\vskip 6 in
\caption{{\protect\footnotesize
The elements of the Chipmunk universe.}}
\label{universe}
\end{figure}



\section{Using the Chipmunks}

The Chipmunks are left powered on at all times, because they can be
damaged by being turned on and off frequently.  Please {\em don't}
touch the power switch (it's the button on the right, underneath the
front of the keyboard).  Chipmunks which are not being used display a
picture or a welcome message.


\subsection{Logging In}

When you have found a Chipmunk no one else is using, insert your disk into
either floppy disk drive, through one of the slots just above the keyboard.
Lift the latch to open the drive, and insert the disk, label upwards and
closest to you.  Close the drive door by pulling the latch down from the top
of the drive until it snaps into position.  If the Chipmunk is showing a
picture, press \key{space} to see the welcome message.  When the welcome
message appears on the screen, follow the directions, and the Chipmunk will
present you with the {\tt *scheme*} buffer in Edwin, running Scheme.  (Read
chapter~\ref{edwin} for an explanation.)  You are now {\em logged in} to the
Chipmunk.

If you are sure a Chipmunk is not being used, but it is not showing the login
screen (either a picture or the welcome message), you should logout and login
anew before using the system, to make sure that it is completely restored to
its fresh state.  This prevents any mistakes made by the previous user from
affecting your work.

\subsection{Directories and Files}

A {\em file} is a bunch of text (English text, Scheme programs, etc.)
that is stored together on a disk.  Each file has a name which must be
unique on the disk.  Here are some typical file names:

\begin{verbatim}
NOTES.TXT    PROBSET1.SCM    ALPHA.SCM
\end{verbatim}

\noindent
The three letters at the end of the name specify, by convention, the type of
information contained in the file.  Files containing Scheme programs have
names ending with {\tt .scm}, and filenames of normal text files end with {\tt
.txt}.  Filenames cannot be longer than sixteen characters.

The list of all the files on the disk is called a {\em directory}, and
Edwin contains commands that enable you to view the directory.

In addition, every disk has a {\em volume name}, which identifies it
as a group of files.  If you are using two disks at the same time (one
in each drive) you use the volume names to distinguish between them.

To refer to a file, specify it by its volume name followed by its
filename; e.g., {\tt MYDISK:PROBSET1.SCM} or {\tt BACKUP:NOTES.TXT}.
If the disk containing the file is the one you logged in with, the
volume name prefix is not required.

\subsection{Initializing the Floppy Disk}

Before a floppy disk is first used, it must be {\em initialized}.  During this
process, the Chipmunk places information on the floppy which will enable it to
find your work later on.  Initialization happens automatically when you log in
with an uninitialized disk; the Chipmunk detects the uninitialized disk and
displays a message asking you whether to initialize it.  Initializing a disk
will erase everything on it, so don't let the Chipmunk initialize a disk if
you think it contains something you want to keep.  In any case, follow the
directions on the screen.

When the Chipmunk initializes a disk, it asks you for a name for the disk (a
{\em volume name}).  Give a short name of the form ``{\sc mydisk:}'' (don't
forget the colon `:').  Initializing takes a few minutes, but you only have to
do it once for each disk you use.  After disk initialization, logging in
proceeds as normal (see above).

\subsection{Loading Problem Sets}

All the files you will need to complete a problem set are available on the
Chipmunk.  To load the files for a particular problem set into the Chipmunk,
use the Edwin extended command {\tt Load Problem Set}; press \key{extend}
(\kkey{2}), then type {\tt load problem set} and press \key{enter}.  Edwin
will ask for the problem set number of the problem set you want; respond by
typing the number, then pressing \key{enter}.

If there are no copies of the problem set files on your disks already, Edwin
copies the ones you may want to change onto your floppy disk.  If there are
already copies on your disk, but they are different from the originals, Edwin
asks whether you want to keep your changed files, or erase them and start over
from the originals.  Follow the instructions on the screen carefully.

In any case, once {\tt Load Problem Set} is finished, a full set of files for
the problem set will be on your floppy disk, and Edwin will have loaded all
the appropriate files for you to examine and modify.


\subsection{Saving Your Work}

Be sure to save your work on your floppy disk before leaving the lab, because
your work is automatically erased from the computer when you log out.

Two different keys can be used for saving buffers in Edwin: \key{save file}
(\kkey{0}) and \key{write file} (\ctrl \shift \kkey{0}).  The \key{save file}
key saves the current buffer to the file from which it was originally loaded.
The \key{write file} key always asks you what filename to use.  If you want to
save an extra copy of a file, use this key.  (See section~\ref{saving-loading}.)

When you save a file on your floppy disk for the second time, Edwin erases the
original copy of the file and replaces it with the new version.  However, it
asks you for permission first:

{\small {\tt File 'MYDISK:PS2-ANS.SCM' exists.  Write anyway (Yes or No)?}}

\noindent
Answer `yes' if you are sure you want to replace the old version with the new
work you have done, and `no' otherwise.

Save your work on disk regularly as you work on problem sets.  If there is a
power outage or computer problem (they don't happen often, but they do
happen), the more recently you've saved your work, the better.

\subsection{Printing text and pictures}
\label{printers}

There are several special keys for making printed text listings of
your work on the text printers.  Type \key{print buffer} (\shift
\key{ins ln}) to print the contents of the entire buffer in which you
are currently working.  (Section~\ref{printing} describes other
commands for printing portions of your work.)
\footnote{If you would like to force a page break somewhere in your paper
listing, you must insert a {\tt \#$\backslash$Page} character into the
buffer you're printing; the {\tt \#$\backslash$Page} character will
appear as {\tt \^{}L} in the file.  To insert the character, type
\shift \key{ins chr}, then \ctrl\key{l}; the {\tt\^{}L} will appear at
the current cursor position.  When you print the buffer, the printer
will insert a page break where the {\tt \#$\backslash$Page} character
appears, and the {\tt \^{}L} will be invisible.}

You cannot use the text printers to make hardcopies of pictures drawn
on the graphics screen.  Instead you must use one of the small inkjet
printers that are attached to several of the Chipmunks throughout the
lab.

To get hardcopy of an image on your graphics screen, you must first
save the image as a ``picture file'' on your floppy disk.  Give the
Scheme command \ide{store-picture}, which requires a file name as
input, for example,
\begin{verbatim}
(store-picture "monalisa.pic")
\end{verbatim}
Later, log in (using your disk) at one of the Chipmunks with an inkjet printer,
and use the Scheme \ide{print-picture-file} command, for example,
\begin{verbatim}
(print-picture-file "monalisa.pic")
\end{verbatim}
{\em Do not use {\tt print-picture-file} on a Chipmunk that does not
have a graphics printer attached}---it will wedge the computer and may
cause you to lose your work.

If you would like to redisplay on the screen an image that you have
presiously saved in a picture file, you can use the \ide{load-picture}
command.  (This does not require a graphics printer.)

\subsection{Logging Out}

When you are finished using the Chipmunk, be sure to log out using the Edwin
extended command {\tt Logout}.  Press \key{extend}, then type {\tt Logout} and
press \key{enter}.  Edwin will find out whether all buffers have been saved on
floppy disk since you changed them, and ask you if you want to save any that
might need saving.

When the picture or welcome message appears on the screen, you are logged out.
Don't forget to take your floppy disk with you.

\section {Chipmunk Status Indicators}
\label{chipmunk-status}
The Chipmunk always displays the time (with a flashing colon `:' between the
hours and minutes) and a status character in the bottom, right-hand corner of
the screen.  There are several possible status characters:

\begin{description}

\item[$^{{\tiny I}}_{{\tiny O}}$] The Chipmunk is ready for you to type
something.

\item[{\tt G}] The Chipmunk is garbage-collecting (cleaning up its memory).
Please wait for it to finish.\footnote{Edwin is written in Scheme.  Like most
Lisp-style languages, Scheme must occassionally stop to {\it garbage collect}.
(See section 5.3 of the 6.001 text for information about garbage collection.)
If Edwin suddenly seems to ``die,'' don't panic; it may just be
garbage-collecting.}

\item[$\pi$] The Chipmunk is running some Scheme code, and is not waiting for
you to type anything.  If you want it to stop, press \key{abort} (see
section~\ref{Trouble}).
\end{description}

\section{Crashes}

The Chipmunk should always be running Edwin.  However, if something goes wrong
with the Chipmunk software, it is possible that the system will ``crash''
while you are using it (see the Cynic's First Law, chapter~\ref{debugging}).
If you cannot get Edwin to respond to anything you type, or if a strange
program suddenly takes over the machine, then Edwin or Scheme may have
crashed.  If this happens, ask a lab TA for help.

If your Chipmunk crashes, and there are no TAs in the lab, you can try to fix
the Chipmunk by pressing \key{shift} and \key{reset} together, then typing
``sb'' (while holding \key{shift} down to make it lower-case), and finally
pressing \key{enter}.  This will ``reboot'' the Chipmunk, completely clearing
its memory, starting it as if it had just been turned on (remember, {\em
never} turn a Chipmunk off).  Only reboot the Chipmunk when it is hopelessly
screwed up, because you will lose all work you haven't yet saved on your disk.
Rebooting takes about five minutes.  Please do not do this when there are TAs
available to help you.

\section{Backing up your disks}

Every experienced programmer has lost files at one time or another.
You will, too.  Files get accidentally overwritten, fuses blow just
when the computer is writing to the disk, armed bandits run through
the computer lab ripping your disks out of the Chipmunks and spiriting
them away; disks get lost, demagnetized, folded, eaten by your
roommate in a fit of exuberance; etc., etc.

Losing files is part of life, like catching a cold, paying taxes, or
having to suffer through overly long problem sets.

Every experienced programmer who is not stupid has learned to back up
his or her files.  Even this will not protect you against a malevolent
universe, but it helps.\footnote{Indeed, there are some who believe
that making backups simply causes the Universe to go to even further
extremes to foil you.  Tom Knight remarks that he is careful never to
keep all backup copies of important files on only one coast of the
United States.}

Please make periodic backups of your work.  The Scheme command
\ide{backup-floppy} will copy the contents of one floppy disk to
another.  When you use this command, follow the instructions
carefully.  In particular, don't confuse the disk that you are backing
up {\em from} with the disk that you are backing up {\em to}.  In this
veil of tears, there is nothing more tragic than an programmer who has
inadvertantly destroyed a disk by attempting to make a backup of it.