Held Friday, September 8, 2000
Summary
Today we begin to learn how to tell Scheme to make decisions. The
procedures used to make decisions are called conditionals.
Notes
- Today's reading: Conditionals
- Today's lab: Conditionals
- Reading for Monday: Recursion
basics (Not yet ready; look for it tomorrow.)
- I'm working with computing services to handle the problems
accessing www.cs.grinnell.edu from ResNet. For now, you might
instead use www.math.grin.edu.
- You might also ask the help desk for assistance setting your DNS
server so that it includes newton.math.grin.edu (132.161.33.70).
- To turn in the homework.
- Go to
http://blackboard.grinnell.edu
- Select this course.
- When prompted to log in, use your normal account as the name
Use a variant of your student ID number as password. Returning
students use the last seven digits of student ID as password.
New students use trailing non-zero digits. [Due to stupidity in
the design of the system, you may be required to log in twice.]
- Click on "Student Tools"
- Click on "Student Drop Box"
- Click on the "Browse" button to select a file.
- Type in something useful, like "Homework 1 from Sam and Max"
- Click on "Send File to Instructor"
- Pray
- Grinnell Entrepreneurs is sponsoring a talk at 4:15 Monday, September
11th in South Lounge. The talk, entitled From a startup to
millions, Grinnell style will docus on issues in starting up a
company with close references to ASI Sign Systems, his own company. Mr.
Latimer brings much valuable insight and perspective from personal
experience. Mr. Latimer is the founder and President of ASI Sign
Systems. Mr. Latimer used to work for the college and he quit in 1985
to start a business of his own in Grinnell. The company specializes
in making signs. For eg: all the signs in the Fine Arts Building are
made by his company. The company has now grown far beyond Grinnell
and is one of the leading ones in the Midwest with offices at various
locations in the midwest.
Overview
- A problem: Assigning grades
- One solution: Using
if
- Another solution: Using
cond
- Lab
- Suppose that for fairness's sake, I'd like a program that converts
numeric grades to letter grades.
- We'll look at two related grading schemes.
- 94-100: A, 90-93: B, 87-89: B+, 84-86: B, ...
- 10:A+ 9:A, 8:A-, 7:B+, 6:B, 5:B-, 4:C+ 3:C 2:C- 1:D 0:F
- How might you explain to someone how to turn a number into a grade?
- In either schema, can you write a procedure that turns a number
into a grade, using only the Scheme you already know?
- As you may have noted from your narrative, we are often tempted
to describe the procedure in terms of the word ``if''. For
example, ``if the grade is at least 94, then give the student
an A, otherwise, if the grade is between 90 and 93, ...''
- In Scheme, you can write such expressions as
(if condition success-value failure-value)
- For example
- We can nest these conditions.
(if (>= grade 94)
'A
(if (<= 90 grade 93)
'Aminus
(if (<= 87 grade 90)
...
)
)
)
- As you may have noticed, the code is somewhat hard to read (and
awfully indented). Another alternative is to use Scheme's
cond
, which more closely resembles a table.
- Here's what a
cond
expression looks like
(cond
(condition value)
(condition value)
(condition value)
...
(else value)
)
- For our problem, this seems particularly appropriate.
(cond
((>= grade 94) 'A)
((<= 90 grade 93) 'Aminus)
...
)