cs150: Notes 4
Assignments Due
- Week of 22 January: Read Chapter
4 and Chapter 5 of the course book.
- (extended from 29 January) Before Monday, 5 February: Read GEB, Little Harmonic Labyrinth and GEB, Chapter 5
- Friday, 2 February (beginning of class): 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.
Why did Alan Perlis say, "A Lisp programmer knows the value of
everything, but the cost of nothing."? (Note: Scheme is a dialect of
Lisp)
PS1 Example Solution
(define brightness
(lambda (color)
(+ (get-red color)
(get-green color)
(get-blue color))))
(define brighter?
(lambda (color1 color2)
(> (brightness color1)
(brightness color2)))
(define color-difference
(lambda (cf)
(lambda (colora colorb)
(+ (cf (- (get-red colora) (get-red colorb))
(cf (- (get-green colora) (get-green colorb))
(cf (- (get-blue colora) (get-blue colorb))))))))
(define (closer-color? sample color1 color2)
(< ((color-difference square) color1 sample)
((color-difference square) color2 sample)))