4. Practice Procedure: pick-one
Define a procedure, pick-one, that takes three inputs. The
first input is a Boolean value (either true or false). If the value
of the first input is true, the output is the value of the second
input; if the value of the first input is false, the output is the
value of the third input.
5. Practice Procedure: middle
Define a procedure, middle, that takes three numbers as
inputs, and outputs the number that is in the middle.
abc
6. a<b
yes
b<c b<c
yes no yes no
b a<c a<c b
yes no yes no
c a a c
13. Practice Procedure: find-fixedpoint
Define a procedure, find-fixedpoint, that takes
as input a function and an initial value, and
outputs the fixed point of the function starting
from that value. A fixed point of a function f is a
value x such that (f x) evaluates to x.
14. Ways to Design Programs
1. Think about what you want to do, and turn
that into code.
2. Think about what you need to
represent, and design your code around
that.
Which is better?
14
15. History of Scheme
Guy Steele co-designed
Scheme, with Gerry
Sussman, and created
the first Scheme
interpreter for his 4th
year project (1975)
More recently, Steele
specified Java [1995]
Guy Steele
15
16. Pre-History of Scheme
Scheme [1975]
Conniver [1973]
Planner [1967]
Based on LISP
[John McCarthy, 1958]
Based on Lambda
Calculus
[Alonzo Church, 1930s]
John McCarthy
17. LISP
“Lots of Insipid Silly Parentheses”
“LISt Processing language”
Lists are really important – hard to write
a useful Scheme program without them.
17
22. Why “car” and “cdr”?
Original (1950s) LISP on IBM 704
Stored cons pairs in memory registers
car = “Contents of the Address part of the Register”
cdr = “Contents of the Decrement part of the Register”
(“could-er”)
Doesn’t matter unless you have an IBM 704
The names “car” and “cons” will come to have mnemonic
significance only when we discuss the representation of the
system in the computer.
John McCarthy, Recursive Functions of Symbolic Expressions
and Their Computation by Machine, Part I, 1960
22
23. Implementing cons, car and cdr
Next class:
how to define cons, car, and cdr ourselves!
23
24. Charge
Quiz Wednesday
Course book through Chapter 4
Gleick’s The Information, Chapters 1-3
Classes 1-5 (including all questions in the class notes)
Class Wednesday and Friday: Lots of examples
and practice programming with procedures
and recursive definitions
24
Notas do Editor
(define middle (lambda (a b c) (if (< a b) (if (< b c) b (if (< a c) c a)) (if (< b c) (if (< a c) a c) b))))