|CSC 153: Computer Science Fundamentals||Grinnell College||Spring, 2005|
|Laboratory Exercise Reading|
This reading reviews some mechanics related to the use of the Mathematics Local-Area Network (MathLAN) for CS 153. The lab also introduces the Scheme environment and introduces Scheme's read-eval-print loop.
More specifically, this lab discusses:
Since you have already programmed in some language on some computer system, some of these mechanics may already be familiar. However, at the very least, you should skim through the first several sections to be sure there are no surprises.
Please pay particular attention to the sections on Scheme and its history.
To use any of the computers in the Mathematics Local-Area Network (MathLAN), one must log in, giving a user name and a password. Contact the instructor if you have questions about this process.
MathLAN computers run the Debian Linux operating system, since this environment provides especially good support for activities related to computer science and mathematics. Debian Linux provides several user interfaces, programs through which one manages various programs and resources that the workstation can access. The recommended user interface is called GNOME. In most cases, GNOME will come up automatically when you log in.
To ensure that the system will use GNOME for your account,
Note: It is not necessary to turn off the workstation when you are finished. MathLAN workstations are designed to operate continuously; turning them off and on frequently actually shortens their life expectancy.
Many materials for this course will be distributed over the World Wide Web rather than in paper copies. To view materials, such as this course's syllabus and this lab, you may follow these steps:
Because URLs are notoriously hard to remember and to type accurately, Firefox allows you to place a bookmark on any interesting or important document that you reach. To place a bookmark on the document currently displayed, move the mouse onto the word Bookmarks above the main display window, click the left mouse button to bring up the corresponding menu, and select the Bookmark This Page... operation. A new window, with the title ``Add Bookmark'' will appear. Move the mouse onto the button marked Add in the new window and click the left mouse button. You can subsequently return to that document by bringing up the Bookmarks menu again and selecting from it the title of the document.
For instance, I recommend that you bookmark the front-door page for this course, so that you can return to it easily, no matter what document is currently displayed.
MathLAN supports several Scheme programming environments. For example, Dr. Scheme may be accessed through the red and blue icon containing the Greek letter lambda, located at the bottom of your workstation's window. Although this system is commonly used at Grinnell, it adds some overhead for this course, and the overhead of learning this system arguably outweighs its advantages. Thus, while you are welcome to experiment with Dr. Scheme, this is not the recommended environment for use in this course.
Rather, the Scheme system that recommended for this course is not represented by any icon on the front panel. To run it, one must invoke it by name. The computer program that reads and responds to such invocations is called the shell, and one's interactions with the shell take place in a window generated by a program called a terminal emulator.
You may already have a terminal window on screen. If not, you can start one at any time by moving the pointer onto the small monitor icon on the bottom row of the front panel, and click with the left mouse button. Shortly a window will appear, displaying the shell prompt -- the name of the workstation on which the shell is running, followed by a percentage sign. This prompt indicates that the shell is ready to receive instructions.
One enters such instructions using the keyboard. Move the mouse pointer into the terminal window to make it active. (You many need to click on the window, once your mouse is in the desired area.) The window frame changes color, indicating that the window has become active.
To shut down terminal, press <Ctrl/d> -- that is, hold down either of the keys marked <Ctrl>, just below the <Shift> keys, and simultaneously press the <d> key. (On our workstations' keyboards, the keys marked <Ctrl> (``control'') and <Alt> (``alt'' or ``meta'') are somewhat like <Shift> keys, in the sense that they modify the effect of other keys that are pressed simultaneously.) The shell program interprets <Ctrl/d> as a signal that you have no more instructions for it and halts, and the terminal terminal emulator closes the window automatically once the shell stops running.
If you want to set the window aside for the moment, with the possibility of returning to it later, look closely at the upper right-hand corner of the window, where the frame contains a small bar or underscore character; if you move the pointer into that square and click on the left mouse button, you minimize the window, closing it up into a small rectangular icon along the bottom control panel on the screen. A minimized window can be restored by moving the pointer onto its icon and clicking the left mouse button twice in rapid succession.
You should change the password associated with your account shortly after you receive it and every few months thereafter. The password program lets you make this change.
After running the password program, the shell takes over again and issues another prompt. You can invoke as many programs as you like from the shell, one after another, before pressing <Ctrl/d> to leave the shell.
Lisp is the second-oldest language still in widespread use (the oldest is FORTRAN). Two dialects of Lisp are widely used today: Scheme and Common Lisp. Scheme is a small, uniform dialect that is good for teaching because of its simplicity. Common Lisp is a large, ``industrial-strength'' dialect that is standardized and is available in several commercial versions. In this course, we will use an implementation of Scheme called Petit Chez Scheme .
Most programming languages require learning the syntax of many different kinds of statements. In contrast, Scheme (and Lisp) syntax is simple and uniform. Much of the work in learning Scheme is learning the names and effects of the system functions that form the core of the language. This course presents the system functions and covers other functions that are present in Common Lisp.
Lisp is especially used for work in Artificial Intelligence. For example, CS 261, Artificial Intelligence, uses programming in LISP in its study of expert systems.
To run the Scheme system, move the pointer into the terminal window, type the word scheme (all in lower-case letters), and press the <Enter> key. Scheme will print out a header and then issue its own prompt (a greater-than sign), indicating that it is ready to examine and process any Scheme program that you submit to it:
Petite Chez Scheme Version 6.0a Copyright (c) 1998 Cadence Research Systems >
To shut down Scheme, press <Ctrl/d> at the Scheme prompt. The shell comes back and generates another prompt once Scheme has stopped.
This read-eval-print cycle forms the basis for all processing within Scheme.
For example, if we type (sqrt 1024) into Scheme, the environment identifies sqrt as an operation to be applied to the number 1024. The computer then evaluates this expression, and concludes by printing the number 32 at the end.
Numbers are expressions, whose value or meaning is the number itself. Scheme recognizes several types of numbers, including the following:
7 -10 3.1415926535
3/5 -18/19 10/34
3.1415926535 10.00 -1.414
(+ 27 3.1415926535) (- 27 3) (/ 17 2) (/ 17 -2) (* 17 2.0) (sqrt 4) (sin 0.5) (sqrt -2) (+ (* 3 2) (/ 8 4))
In Scheme, symbols may act as variable names, but they do not have a value until we give them one.
Binding: We may give a symbol a value using a define operation. For example, we might give the symbol pi the value 3.141592 as follows:
(define pi 3.141592)
Similarly, we can give the symbol radical-2 the value of the square root of two as follows:
(define radical-2 (sqrt 2))
When using define, the symbol is given the current value of the expression that follows.
This document is available on the World Wide Web as
created December 29, 1996 by John David Stone
last revised January 23, 2005 by Henry M. Walker
|For more information, please contact Henry M. Walker at firstname.lastname@example.org.|