Assignments Due
- Now: Problem Set 1
- Friday, 4 September: Read through the end of Chapter 4
- Monday, 7 September: Read through the end of Section 5.4
- Wednesday, 9 September: GEB
Reading
- Monday, 14 September: Problem Set 2
Two especially useful DrScheme commands:
- [Tab] — Press the [Tab] key for DrScheme to indent your code
structurally. All your code should be divided into logical lines that
fit in the page with, and indented to show its structure clearly. To
indent all your definitions, use Ctrl-I.
- Esc-P — In the interactions window, use
Esc-P to retrieve your last command. To go further back, press
Esc-P again. This saves typing when you are trying different
things.
Evaluation Rules
Using the evaluation rules (from last class and Chapter 3), explain (in
tediously gory detail!) how each of these expressions is evaluated (for
some expressions, you may need more space than is available here):
- true
- (* 2 (+ 1 2))
- (lambda () true)
- ((lambda () true) 3)
- ((lambda (a) (+ a a)) 3)
- (((lambda (a) (lambda (b) (+ a b))) 1) 2)
Defining Procedures
- First, make sure you know what the procedure is intended to do.
You should know what the inputs are (and what types of values they are),
and what type of value the output is (e.g., a procedure, a number, a
list). You should also have some example inputs and outputs in mind.
- Before worrying about the code, think in English how you will solve
the problem.
- Define the procedure.
- Test your procedure with the example inputs and outputs. Think
about any tricky cases that you should also test.
Procedure Practice
Xor. Define a procedure, xor, that implements the logical
exclusive-or operation. The xor function takes two inputs, and
outputs true if exactly one of those outputs has a
true value. Otherwise, it outputs false. For example,
(xor true true) should evaluate to false and (xor
(< 3 5) (= 8 9)) should evaluate to true. (Exercise 3.8 from
book)
Middle. Define a procedure, middle, that takes three
numbers as inputs, and outputs outputs the number that is in the
middle. For example, (middle 1 2 3) should evaluate to
2 and (middle 1120 150 200) should evaluate to
200. (Before defining your procedure, consider carefully if
the problem is sufficiently well defined.)