Goals: This lab 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 section on Netscape Options and all sections on Scheme.
To use any of the computers in the Mathematics Local-Area Network, one must log in, giving a user name and a password. Contact the instructor if you have questions about this process.
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:
Each MathLAN user can configure Netscape Navigator to reflect his or her own preferences. Between logins, these preferences are stored in a file in the user's home directory; when Netscape Navigator is started during a later session, they are reinstated from that file.
Every user of Netscape Navigator on MathLAN should at some point perform two specific configuration steps:
Establish a base page -- a starting point for browsing. Here are the Uniform Resource Locators or URLs of some good choices:
To establish your base page, bring up the Edit menu from the menu bar and select the Preferences operation. A pop-up window appears, allowing you to configure many features of the general appearance of Netscape Navigator. Choose the Navigator option. The rectangle labeled Home Page Location contains the URL of the ``Welcome to Netscape'' document at Netscape Communications Corporation; this is what Netscape Navigator uses by default as a base page. Replace the contents of this rectangle with one of the URLs shown above. (This does not have to be a permanent change; you can change your mind about this configuration at any time within Netscape Navigator.)
To erase the current contents of the Home Page Location box, move the mouse pointer to the left of the first character in the box, press the left mouse button and hold it down, and drag the mouse pointer rightwards until the entire URL is displayed in reverse video, white letters on a black background. Then release the left mouse button and type the new URL; the old one will vanish as soon as you start typing. Once you have entered the new URL, move the mouse pointer onto the button marked OK at the bottom of the pop-up window and click on it with the left mouse button.
To reduce the size of the disk cache, bring up the Edit menu again and select the Preferences operation. Again a pop-up window appears. Click on the right-pointing triangle next to Advanced and then click on the Cache option. Erase the number (typically 5000) that appears in the rectangle labeled Disk Cache and replace it with 0. Finally, click on the OK button at the bottom of the pop-up window.
The Scheme system that we shall use in 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. The particular terminal emulator that we shall use is named dtterm.
You may already have a dtterm window on screen. If not, you can start one at any time by moving the pointer onto the small monitor-and-keyboard icon, fourth from the right 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 types in such instructions using the keyboard. Move the mouse pointer into the dtterm window to make it active. Notice that the window frame changes color when the pointer crosses it, indicating that the window has become active.
To shut down dtterm, 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 dtterm 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 square with a dot in it; 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 left-hand edge of 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 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 dtterm 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:
To shut down Scheme, press <Ctrl/d> at the Scheme prompt. The shell
comes back and generates another prompt once Scheme has stopped.
Numbers are expressions, whose value or meaning is the number
itself.
This document is available on the World Wide Web as
created December 29, 1996 by John David StoneRunning Scheme:
Chez Scheme Version 5.9i
Copyright (c) 1998 Cadence Research Systems
>
Numbers in Scheme
This
read-eval-print cycle forms the basis for all processing within
Scheme.
Type several numbers into Chez Scheme, typing one number at a
time. For example, at the Scheme prompt, type
7
-10
3.1415926535
In each case, note how Chez Scheme responds.
3/5
-18/19
10/34
How many digits are printed in the answer for rational numbers?
(- 27 3)
(/ 17 2)
(/ 17 -2)
(/ 17 2.0)
(truncate (/ 17 4))
(modulo 17 3)
(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. Describe what happens when you type one of the
above symbols into Scheme.
hi TwoBeOrNot2Be This-is-a-symbol.
(define pi 3.141592)
Now enter pi into Scheme and determine what happens.
(define pi 3)
Now what happens if you type the symbol pi?
(define a 4)
(define b 5)
(define c 1)
(define discriminant
(- (* b b) (* 4 (* a c))))
(define root1
(/ (+ (- b) (sqrt discriminant))
(* 2 a)))
(define root2
(/ (- (- b) (sqrt discriminant))
(* 2 a)))
Determine the values for a, b, c, discriminant, root1, and
root2 .
http://www.math.grin.edu/~walker/courses/153.sp00/lab-getting-started.html
last revised January 7, 2000 by Henry M. Walker
Henry M. Walker (walker@math.grin.edu)