Fundamentals of Computer Science I (CS151.02 2007S)
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151 2006F (Rebelsky)]
[CSC151.01 2007S (Davis)]
[CSCS151 2005S (Stone)]
This lab is also available in PDF.
Many of the fundamental ideas of computer science are best learned by reading, writing, and executing small computer programs that illustrate them. One of our most important tools, therefore, is a program-defvelopment environment, a computer program designed specifically to make it easier to read, write, and execute other computer programs. In this class, we will often use a programming environment named DrScheme.
Note: Each member of your group should do this step of this lab working within his or her own account.
Short Version
drscheme
.
PLTso that it points down.
Pretty Big.
To start DrScheme, click the mouse on the large, round, red icon
containing the Greek letter lambda in the middle of the control panel.
(If you don't have the lambda, you can open a terminal window and type
drscheme
. In case you've forgotten, to open a terminal,
click on the picture of the computer monitor with a foot on it.)
The first time you start DrScheme, it will ask you what human language you'd
like to use. For this class, you should probably select Interact
with DrScheme in English
.
DrScheme may also ask you what version of Scheme (which it also calls
a language
) to use. We explore a lot of Scheme in this course, so
we'd like you to use one of the biggest versions, Pretty Big Scheme.
To select that version, you first need to expand the list under
PLT
, which you can do by clicking on the triangle
next to PLT
so that it points down. You can then
click on Pretty Big (includes MrEd and Advanced)
.
Sometimes DrScheme just yells at you to choose a language, but doesn't prompt you immediately. In that case, select
from the menu and follow the steps in the preceding paragraph. Once you've followed those steps, you must also click the button.Once you've selected a version of Scheme, click on the
button.Shortly, DrScheme will start up and appear as a new window, with two white rectangular text areas against a dark gray background.
At the top of the window, just below the frame, is a menu bar, providing ways of activating various operations that DrScheme can perform. Eventually we'll explore a number of these, but for the moment let's just look at one that you're certain to need: the operation of shutting itself down.
Move the mouse pointer onto the word
at the left end of the menu bar and click the left mouse button. A small menu appears.Move the mouse pointer onto the word
at the bottom of this menu and click the left mouse button. DrScheme responds by popping up a confirmation box of its own, the purpose of which is to make sure that you don't shut down DrScheme by mistake.Move the mouse pointer onto the word
in the confirmation box and click the left mouse button. Both the confirmation box and the main DrScheme window disappear.Note: Each member of your group should do this step of this lab working within his or her own account.
Short Version
PLTso that it points down.
Pretty Big.
DrScheme retains the information that you prefer to use Pretty Big Scheme, so that when you log in again tomorrow and start DrScheme again, it will automatically expect programs in that dialect. You won't need to change the language again unless you decide that you'd like to experiment with Beginning Student Scheme or some other dialect.
Short Version
(sqrt 144)
(+ 3 4)
(+ 3 (* 4 5))
(* (+ 3 4) 5)
(string-append "Hello" " " "Sam")
As you may remember from the reading on DrScheme, the DrScheme window has two panes, one for definitions and one for interaction. Just as in the reading, we'll begin by considering the interactions panel.
The best way to understand the interactions pane is to use it. So, let's try the first few examples from the reading. Type each in the pane, hit return, and see if you get the same value.
> (sqrt 144) 12 > (+ 3 4) 7 > (+ 3 (* 4 5)) 23 > (* (+ 3 4) 5) 35 > (string-append "Hello" "Sam") HelloSam
Short Version
(sqrt 137641)
.
Of course, the computer is using some algorithm to compute values for the expressions you enter. How do you know that the algorithm is correct? One reason that you might expect it to be correct is that DrScheme is a widely-used program (and one that I've asked you to use). However, there are bugs even in widely-used programs. You may recall a controversy a few years back in which it was discovered that a common computer chip computed a few specific values incorrectly, and no one had noticed.
Hence, each time you do a computation, particularly a computation for which you have designed the algorithm, you should consider how you might verify the result. (You need not verify every result, but you should have an idea of how you might do so.) When writing an algorithm, you can then also use the verification process to see if your algorithm is right.
Let's start with a relatively simple example. Suppose we ask you to ask DrScheme to compute the square root of 137641. You should be able to do so by entering an appropriate Scheme expression:
> (sqrt 137641)
Scheme will give you an answer. How can you test the correctness of this answer? What if you don't trust DrScheme's multipliciation procedure? (Be prepared to answer this question for the class as a whole.)
Short Version
As you may recall from the reading, the upper text area in the DrScheme
window, which is called the definitions pane, is used when
you want to prepare a program off-line
, that is, without
immediately executing each step. Instead of processing what you type
line by line, DrScheme waits for you to click on the button labelled
(the second button from the right, in the
row just below the menu bar) before starting to execute the program
in the definitions pane. If you never click on that button, fine --
your program is never executed.
Warning: When you click on the
button, the contents of the interactions pane are erased. The idea is that executing the program in the definitions pane may invalidate the results of previous interactions. Erasing the results that may now be inconsistent with the new definitions ensures that all visible interactions use the same vocabulary. This is actually a helpful feature of DrScheme, but it can take you by surprise the first time you see it happen. Just make sure that you have everything you need from the interactions pane before clicking on .Let's try using the definitions pane. First, enter the following in that pane.
(define grade1 90) (define grade2 67) (define grade3 80) (define grade4 85) (define grade5 100) (define grade6 91)
Next, try computing the average in the interactions pane.
> (/ (+ grade1 grade2 grade3 grade4 grade5 grade6) 6)
reference to undefined identifier: grade
It is likely that you will get an error message, just as the example suggests. Why? (Please make sure you have an answer before going on.)
Next, click <Esc>+<P> will bring back the previous expression.)
and try entering the expression again. (Remember,
Let's try another definition. Define name
as your name in
quotation marks. For example,
(define name "SamR")
Click <Run> and then find the value of the following expression.
> (string-append "Hello " name)
Let's make sure that you can save and restore the work you do in the definitions pane.
(/ (+ grade1 grade2 grade3 grade4 grade5 grade6) 6)
(string-append "Hello " name)
Let's try using the definitions you created without having them open in the definitions pane.
(load "grades.ss")
(/ (+ grade1 grade2 grade3 grade4 grade5 grade6) 6)
(string-append "Hello " name)
Throughout the semester, you will find yourself defining a number of
values (including algorithms, which Scheme considers values). So that
you don't have to go back to lots of places to look for things you've
done before, I suggest that you create a file, library.ss
in which you enter values and other stuff that you'll need again and
again.
Create that file, and give it two values, first-name
, which
should have the value of your first name, and last-name
,
which, should have the value of your last name.
For example,
(define first-name "Sam") (define last-name "Rebelsky")
While we would prefer that you do your work for this class in the MathLAN
so that you have a support network available (that is, the tutors, your
instructor, and your classmates), it is possible to run DrScheme on
almost any computer, including Macs and PCs running Microsoft Windows.
You can download a copy from http://www.drscheme.org
.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/History/Labs/drscheme.html
.
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151 2006F (Rebelsky)]
[CSC151.01 2007S (Davis)]
[CSCS151 2005S (Stone)]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Thu Sep 13 20:54:18 2007.
The source to the document was last modified on Tue Jan 23 17:17:32 2007.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007S/Labs/drscheme.html
.
You may wish to
validate this document's HTML
;
;
http://creativecommons.org/licenses/by-nc/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.