Held: Tuesday, 23 February 2016
Back to Outline 17 - Boolean Values and Predicate Procedures.
On to Outline 19 - Naming Local Values.
Summary
We begin to explore Scheme's conditional control structures,
particularly if, when, and cond.
Related Pages
Overview
- The parts of an algorithm, revisited.
- Choosing between two options with
if.
- Optional evaluation with
when.
- Making multiple choices with
cond.
- Comparing approaches.
Administrivia
- Continue partners.
- Quizzes returned.
- We'll continue to talk a little bit about testing.
Reminders
- Office hours: MTWF 10-11, Tu 1-2.
- Tutor hours
- Sunday, 3-5 p.m.
- Sunday-Thursday, 7-10 p.m.
- Weekly review sessions:
- Wednesday at 8pm in the CS Commons with Sarah
- Thursday at 10am in this room with SamR
- Thursday at 8pm in the CS Commons with Alex
Upcoming Work:
- Reading for Wednesday
- Assignment 5 due TONIGHT
at 10:30 p.m.
- Lab Writeup: Exercise _
- Send email titled CSC 151 Lab Writeup 18 (Your Names)
- Do not include the underscores.
- Send to CSC151-02-grader@grinnell.edu
- Due before class on Monday.
Extra Credit
- Send your reports to rebelsky@grinnell.edu with subject
"CSC 151 Extra Credit". (Do not include the quotation marks.)
- Send opportunities to me before class with subject
"CSC 151 EXTRA CREDIT OPPORTUNITY!"
Academic
- Town Hall, Wednesday 7:30 pm in JRC 101
- CS Extras, Thursday: ????
Peer
- Go to Wednesday's SGA meeting at 8:30 p.m in JRC 209 to make noise
about the reserve.
- Pun Club Tournament Friday the 26th in the evening.
- Contra Dance Friday the 26th in the evening.
- Improv Show the 27th in the evening in Loose Lounge.
- AppDev Pub Night, Friday, 8pm, Lyle's (JRC Basement).
- Black History Month Showcase, Friday, Harris, 7:30 p.m.
- Vote for SGA positions.
Regular Peer
- Social Dance Workshop Tuesdays 7:00-8:00 in Bucksbaum Dance Studio
- Pun club Saturdays at 4pm in Younker
- Electronic Potpourri on KDIC Fridays at Five
- Space Odyssey KDIC Fridays at Six
Misc
- Christine Tran show in Smith Gallery.
No Extra Credit, But Still Good
The Parts of an Algorithm
Remember those? We did them early on in the semester.
- You need to have some basic operations.
- You need to be able to sequence your operations, explicitly
or implicitly.
- It's nice if you can name values.
- You need to be able to write subroutines (aka procedures) that
parameterize a piece of code.
- You need to be able to repeat instructions.
- You need to be able to choose between options.
How many of these do we know? Almost all of them.
Choosing Between Options with if
- The first mechanism for choice.
- Form
(if TEST CONSEQUENT ALTERNATE)
- Meaning
- Evalute the TEST.
- If the TEST is not false ("holds"), evaluate and use the value
of the CONSEQUENT.
- If the TEST is false, evaluate and use the value of the ALTERNATE.
- Note:
- You only get one consequent
- You only get one alternate
Optional Evaluation with when
- Useful only when you're sequencing operations.
- Form
(when TEST CONSEQUENT_1 CONSEQUENT_2 ... CONSEQUENT_n)
- Meaning
- Evaluate the TEST.
- If the consequent is not false ("holds"), evaluate each
of the consequents in turn. Use the value of the last
consequent.
- If the consequent is false, do nothing. Return nothing.
- Note:
- You get as many consequents as you want.
Choosing Between Multiple Options with cond
Comparing Approaches
- Returns a value:
cond and if.
- Lets you have multiple consequents:
when and cond.
- Let's you choose between options
cond and if.