Spring 1996
To install the Comp 210 computing environment, type
register comp210followed by pressing the Return key, and answer any questions that you are asked. If you have never installed an OwlNet environment before, you should not be asked any questions other than ``Are you sure ...'', to which you respond by typing yes followed by Return. Now log out and log in again to start a session which uses the Comp 210 computing environment.
Each time you log off your machine, first make sure that you have saved any Scheme program text that you want to keep in a file. Then type the command exit followed by Return in the console window in the upper left corner of your screen.
How you run the environment depends on what kind of machine you are logged into. If you are logged into an X terminal, you probably already see at least one text window, plus a background of a different color. If you are logged into a workstation (like the SPARCstation 5 machines in the front of Ryon 102 and the SPARCstation 4 machines in its rear), then you see a blank white screen with a Unix prompt at the left. Type
startxfollowed by Return to start the X Windows environment. (When you log into an X terminal, X Windows is started automatically; no startx command is required.)
You can start programs either by typing their names in a command shell or by using the mouse to invoke a menu and then selecting the name of the desired program. The console window in the upper left corner of your screen is a command shell, but we generally use it only to read system messages and to log out. To start an additional command shell, either
xterm &
into a command shell, followed by Return,
orSometimes when you start a program, the system asks you to choose a location for the program's window by displaying a wireframe outline of the window. To place the window where you want it, move it with the mouse, then left-click (press the left mouse button).
Netscape is a window-based program that displays hypertext documents from the World-Wide Web. (Another such program is Mosaic.) Hypertext documents can contain text, pictures, sound, movies, and links to other documents. The World-Wide Web (WWW) is an interconnected collection of hypertext documents. The act of browsing the World-Wide Web of documents is called ``Web surfing'' or ``net surfing.''
To run Netscape, either
netscape &
into a command shell, followed by Return,
or&
at the end of the
command line means ``don't wait for me to finish this program
(Netscape, in this case) before letting me issue another shell
command.'')
The first time that you use Netscape, it will display a license agreement. Read it and click on the Accept button. Netscape will subsequently display an Error window stating your account has not yet been initialized for Netscape. Click on the OK button to initialize your account; Netscape will respond by creating some special files in your account (their names start with a period, so they are ignored as uninteresting by many Unix programs) and displaying the ``home page'' for Comp 210.
In a hypertext document from the World-Wide Web--sometimes called a WWW page--phrases highlighted by color and underlining are linked to other pages. You can see the associated page for a given phrase by moving the mouse cursor to point to the phrase and clicking the left mouse button. The new page, which might be located on any computer in the world which is connected to the global Internet network, replaces the old page in the window. To return to the previous page, simply click on the button Back at the top of the window.
You can directly access an arbitrary Web document by clicking the Open button at the top of the window or by just typing into the ``Location'' edit box near the top of the Netscape window. Fortunately, you rarely have to specify an explicit location (or URL in WWW jargon) while net surfing.
If you find a document of particular interest, you can save its title and URL in your Bookmarks menu. To do this, pull down the Bookmarks menu and select Add Bookmark. This document can be revisited in later sessions by selecting its title in the Bookmarks menu.
In order to see the most recent version of a document, click on the Reload button. You may need to do this sometimes, because Netscape remembers the contents of some pages so that it can display them without retrieving them from the Internet; but it sometimes fails to notice that the remote copy has changed in the meanwhile.
You can exit Netscape by pulling down the File menu and selecting the Exit command. Try it. Then restart Netscape.
After lab, you should look through the Comp 210 home page, which contains
office hours, homework, a link to the course newsgroup, lecture notes for
last year, and more. The Comp 210 home page is displayed whenever you
start Netscape and is also available by clicking on the
Home button near the top of the
Netscape window. Its URL is
http://www.owlnet.rice.edu/~comp210
.
Comp 210 uses a bulletin board system called netnews for communication among students and staff. From the Comp 210 homepage, click on the rice.owlnews.comp210 link. You will see a large number of articles, most from old terms and not of interest to you. To read an article (such as the one near the end titled *** SPRING 96 STARTS HERE ***), click on it. When reading an article, you can click on the downarrow picture to see the next article and the uparrow picture to see the previous article. The left and right arrow pictures take you to the previous and next articles on the same topic as the one you're reading. (Click on the This Newsgroup button to see the list of all articles.)
Once you have read all the articles after *** SPRING 96 STARTS HERE ***, go back to the list of articles and click on Mark all articles read. This will prevent messages from previous versions of the class from being displayed in the future; by default, only new articles are displayed. You can show even the articles you've read (or marked as read) via the Show Read Articles button.
When replying to an article, choose carefully between posting a reply, which adds a new article to the newsgroup for everyone to see, and mailing a response only to the author of the article you are reading.
Remember that you can return to the Comp 210 home page at any time by clicking the Home button near the top of the Netscape window).
There are thousands of other newsgroups which you can participate in. We recommend that you read a group for a while before posting articles to it, so that you understand the group's flavor and don't do something inappropriate. (For instance, alt.computers.religion is not about automating church offices, but is a forum for humorous ``religious wars'' between proponents of different varieties of computers such as IBM vs. Mac.) You should also read the FAQ (Frequently Asked Questions) for the group so you don't repeat a common request, and consider reading news.announce.newusers, which contains other information for new users of netnews.
In Netscape, click on the link entitled Labs. On the new page that appears, click on the entry Lab 1 to see a copy of this document displayed in a new window using a tool called Ghostview. The lab handout is not a hypertext document; it is expressed in a format called PostScript. Ghostview is a PostScript document reader.
In Ghostview, the space bar displays the next page; the Delete or Backspace keys display the previous page. You can also invoke these operations from the Page menu. You can exit Ghostview by typing q or pulling the down the menu titled File and selecting the Quit command.
You can print out a copy of a document by pulling down the File menu and selecting the Print command. The program will ask you for a printer name; usually you can just accept the default. The name ryonps identifies the printer in Ryon. Laser printing costs 5 cents a page. You can can print the single page in view by typing the character p.
If you click the mouse in the Ghostview window, Ghostview will display a window which zooms in on (displays, magnified) the part of the document where you clicked. Unless you're editing a document and want to see just how a figure or some text looks, you probably don't want this; click the Dismiss button at the bottom of the Zoom window.
Quit Ghostview now and click on the Back button in your Netscape window. At this point, you should be viewing the Comp 210 home page again.
There are many different Unix programs (called ``mailers'') that send and
receive electronic mail. The most popular mailers on Owlnet are Pine and
Elm. To invoke Pine, type pine &
at a Unix command prompt or move
the mouse to the stippled background, click the right button to produce a
menu of programs, and select the pine command in the submenu
entitled mail. Pine gives you step-by-step instructions on how to
read and send mail.
Windows typically have title bars at the top. These title bars contain two special small boxes: a ``bulls-eye'' (a large dot inside a box) on the extreme left and a ``baseball diamond'' (three nested squares) on the right. You can use the title bar to perform the following operations on windows:
When we say ``left-click'' on an object, we mean to move the mouse so that the mouse cursor is over the object, then press and release the left mouse button without moving the mouse. To ``drag'' an object, move the mouse cursor over it, press the specified mouse button (the left one, by default), move the mouse (you will probably also see the object move), and then release the mouse button.
To type text into a window you must move the mouse cursor inside that window. Whenever you type text, it is directed at the tool determined by the position of the mouse cursor. If the mouse cursor is not inside any window, the typed text is ignored.
We will use three different environments for evaluating Scheme expressions and running Scheme programs. These are DrScheme, Donkey, and Emacs; each has its own strengths and weaknesses. For instance, DrScheme is good for editing Scheme files and locating errors in them; Donkey is a special-purpose tool for watching the computer evaluate Scheme programs in ``slow motion''.
Emacs is a powerful text editor that also serves as a programming environment. You can use it to read mail and news, edit and execute programs, and much more--in fact, many people do all their online work from inside Emacs. When editing C programs, we will use Emacs exclusively; and it can also be used to run Scheme. However, we will start out with more specialized tools, so we will defer discussion of Emacs until later in the term.
DrScheme combines a text editor with a Scheme interpreter. You
can run DrScheme via the left-button mouse menu, or you can type
DrScheme at the command line. (Don't forget to add &
if you want
to issue other commands before you're done with DrScheme.)
The DrScheme window is subdivided into two subwindows (or
``panes''). In the upper pane (informally called the ``dictionary''), you
can enter definitions for names; in the lower pane, you can enter
expressions to be evaluated at the ``|-
'' prompt. Scheme does not
learn definitions in the upper pane until you click on the Execute
button. You can check to see if your definitions are well-formed by
clicking on the Check Syntax button, but DrScheme does
not require you to check program syntax before executing it.
Donkey is a different interface to Scheme; instead of having two separate windows, there is only a single window for all interactions with Scheme. Each expression appears in a box, with its value (if any) beneath it. The current expression is displayed in a bold blue typeface. You can evaluate an expression by typing it, then pressing Return, or by clicking on the Eval button. Next lab we will learn about Donkey's powerful features for watching the substeps in the evaluations of a procedure.
From Donkey, you can start DrScheme by using the DrScheme menu; and then the two programs can share programs.
Remember that to enter text in a particular pane (such as the DrScheme evaluation pane, or a particular Donkey boxed block), you must move the click mouse cursor within that pane (and keep the mouse cursor in the DrScheme window). If you make a typing mistake, you can delete the last character typed by pressing the Delete key.
If you don't see anywhere to type an expression to Donkey, select the Insert Block item from Donkey's Edit menu. You can use Clear Block from the same menu to remove a block (Donkey's name for an expression and its result, which lie between horizontal lines on the screen).
Arithmetic expressions in Scheme are defined using prefix notation. Prefix notation avoids the ambiguities in the ordering of operations in conventional mathematical notation. For example, is 1-2+3 equivalent to (1-2)+3=2 or 1-(2+3)=-4? In prefix notation, expressions are either constants like 0, -12, or 3.14, or they are composite expressions of the form
(operator arg1 ... argN) .The available set of operators includes all of the usual arithmetic operators like +, -, * (multiplication), and /. For example, the expressions (+ (- 1 2) 3) and (- 1 (+ 2 3)) are the prefix versions of two interpretations of 1-2+3 given above. Try evaluating these two Scheme expressions and some examples of your own.
Scheme does an excellent job of evaluating numeric operations--for instance, (/ 1 3) evaluates to the rational number 1/3 rather than to an inaccurate floating-point approximation such as 0.33333333. Similarly, Scheme can handle very large numbers. Try
(* 27182818284590455 31415926535897931)and some examples of your own.
Scheme computes with many different kinds of data--not just numbers. The boolean values #t and #f signify the values ``true'' and ``false''. The standard relational operators =, <, >, <=, and >= all have their usual mathematical meanings, but the must be used in prefix position like all Scheme operators. Try evaluating the expressions
(= 6 6) (= 6 7) (= 100 (* 10 10)) (< 6 7)and some other examples of your own. For some expression including more than one operator--such as
(= 100 (* 10 10))
--press the
Step button of Donkey, and continue to do so until you
reach the answer.
Relational operators take numbers as inputs and produce boolean values as outputs. Some other Scheme operators take boolean values as inputs and produce boolean values as outputs; they include not, and, and or. Try evaluating
(not #t) (not #f) (and #f #t) (or #t #t)and some examples of your own.
Symbols are another simple form of Scheme data. A symbol is a sequence of characters preceded by a single forward quotation mark ' (the unshifted double quote mark). Some examples include 'dollar 'cents 'John 'Vladimir. The most common operation performed on symbols is equality testing, signified by the operator eq?. (The = operator tests the equality of numbers; it does not work on symbols.) Try evaluating
(eq? 'John 'John) (eq? 'John 'john) (eq? 'John 'Vladimir) (= 'A 'A)and some examples of your own.
A more interesting form of Scheme data is the list. A list is of a (possibly empty) sequence of elements, which can be arbitrary Scheme data values. The empty list is designated null, which is a constant just like #t and 5.7 and which evaluates to itself.
More interesting lists are constructed from null using the operator cons (which stands for ``construct list''). cons takes a data value v and a list l and constructs a new list identical to l except that it has the additional element v on the left end. Try evaluating the expressions
(cons 2 (cons 'cents null)) (cons 4 (cons 'dollars (cons 2 (cons 'cents null))))and some examples of your own.
DrScheme and Donkey represent lists slightly
differently. DrScheme represents the result of
(cons 2 (cons 'cents null))
as (list 2 'cents)
, while
Donkey represents the result as '(2 cents)
.
Later in the course, we will see that either of these forms can be used as
a more compact way to construct lists than using cons.
The if operator makes choices. It takes three arguments: a boolean and two other values. If the boolean (the first argument to if) is true (#t), then the value of the if expression is the value of its second argument. If the boolean is false (#f), then the value of the if expression is the value of its third argument. Evaluate these expressions, and some examples of your own:
(if #t 'the-answer 'impossible) (if #f (/ 4 0) #t) (if (> 5 4) 5 4)
In Scheme, a definition associates a value with a name. Like expressions, definitions are written in prefix notation. For example, the program text
(define Pi 3.1415927) (define PiSq (* Pi Pi))makes Pi a name for the value 3.1415927 and PiSq a name for the value 9.86960469269329.
In DrScheme, you would either enter those forms into the dictionary pane, then click the Execute button, or enter those forms into the expression pane. In Donkey, you enter definitions just as you do ordinary expressions.
After evaluating those definitions, if you then evaluate the name PiSq, Scheme returns the value 9.86960469269329.
The define operator can also associate functions with names, as we will see in the second lab section.
In the process of typing Scheme definitions and expressions, you will inevitably make some mistakes. Three kinds of errors (besides typing errors) are particularly common.
First, you may refer to an undefined variable in an expression. For example, you might ask Scheme to evaluate
(+ 2 undefined)where the name undefined has not been defined. In this case, DrScheme will print an error message and move the cursor to identify the place in your program text where the error occurred; Donkey will display an error message at the bottom of the window.
Second, you may try to perform a meaningless operation such as dividing by zero. Again, the Scheme environments will react similarly: each will print an error message, and DrScheme move the cursor to identify the place in your program text where the error occurred.
Third, you may not match parentheses in expressions. Scheme expressions can be split over several lines. As a result, typing
(+ 2 2followed by Return in Donkey or the DrScheme evaluation window causes Scheme to wait without explanation. You must type a closing parenthesis followed by Return. Scheme then returns 4. The DrScheme dictionary window is kinder. If you click on the Execute or Check Syntax buttons when the dictionary pane contains an unbalanced parenthesis, it will detect the error, display an error message, and move the cursor to the expression containing the missing (or extraneous) parenthesis.
Try making some mistakes and see how Scheme responds. On occasion you may create programs that ``run away'' or ``infinite loop'', never stopping without outside intervention. To stop such a program, press shift-control-c (hold the shift and control keys, then press and release c, then let up on shift and control. It may take a few seconds for this to take effect, so be patient. DrScheme has an additional method for accessing this functionality: click on the Stop Executing button at the top of the DrScheme window. You may have to click on it several times to stop your program.
You can save your definitions using the commands Save or Save As... on the File menu. The command will prompt for the name of the file in which to save your definitions. You can choose any file name that you want, but the usual convention for Scheme programs is to choose a name ending in the three characters `.ss'.
To resume working on a file that you have saved, choose the Open command in the File menu. DrScheme or Donkey will pop up a new window with a list of your files; select one and click on the OK button. DrScheme will copy the file into the dictionary window, where you can edit it and subsequently load it into Scheme using the Execute command. Donkey will evaluate each expression in the file, in turn.
When you finish a session, you can exit using the Quit or Close command on the File menu. If you have entered any definitions in the dictionary window but have not saved them, DrScheme will ask you if you really want to quit and force you to click on a button titled Quit anyway to quit.