Warning! You are being recorded and transcribed, provided the technology is working correctly.
We are back to the standard start-of-class procedure.
Approximate optimistic overview
Scholarly
Artistic
Multicultural
Peer
Musical, theatric, sporting, and academic events involving this section’s students are welcome.
Wellness
Misc
These do not earn tokens, but are worth your consideration.
Brand new! Please keep me posted on confusing or long parts.
Summary: Like mini-project 3, but with conditionals.
Also:
What is (and)
? Why?
What is (or)
? Why?
is-even?
Here’s how many people defined is-even?
.
(define is-even?
(lambda (val)
(if (= (remainder val 2) 0)
#t
#f)))
But the #t
and #f
are icky. Let’s think about a better way.
If val
is even, what do we get from (= (remainder val 2) 0)
? #t
If val
is odd, what do we get from (= (remainder val 2) 0)
? #f
(define is-even?
(lambda (val)
(= (remainder val 2) 0)))
zero?
(define is-even?
(lambda (val)
(= (remainder val 2) 0)))
We make it a little clearer using the amazing zero?
predicate.
(define is-even?
(lambda (val)
(zero? (remainder val 2))))
Can we make that even more concise with cut
and composition?
(define is-even?
(o zero? (cut (remainder <> 2))))
is-even-integer?
Here’s one approach.
(define is-even-integer?
(lambda (val)
(and (integer? val) (zero? (remainder val 2)))))
Can we do better?
(define is-even-integer?
(lambda (val)
(and (integer? val) (is-even? val))))
Reminder: Once you’ve written a procedure and need something similar in another procedure, call the previous procedure, don’t copy the body.
(define median-of-three
(lambda (x y z)
(cond
[(or (<= x y z) (<= z y x))
y]
[(or (<= y x z) (<= z x y))
x]
[(or (<= x z y) (<= y z x))
z])))
Hmmm … shouldn’t we have a default?
(define median-of-three
(lambda (x y z)
(cond
[(or (<= x y z) (<= z y x))
y]
[(or (<= y x z) (<= z x y))
x]
[(or (<= x z y) (<= y z x))
z]
[else
#f])))
Or, better yet,
(define median-of-three
(lambda (x y z)
(cond
[(or (<= x y z) (<= z y x))
y]
[(or (<= y x z) (<= z x y))
x]
[else
z])))
If we didn’t have if
or cond
, we could write
(define median-of-three
(lambda (x y z)
(or (and (or (<= x y z) (<= z y x))
y)
(and (or (<= y x z) (<= z x y))
x)
z)))
No, I don’t want you to take this last approach.
There’s also a math-based trick.
(define median-of-three
(lambda (x y z)
(- (+ x y z) (min x y z) (max x y z))))
One solution to 2b.
(define dark-circles
(apply beside
(map thickly-outlined-circle
(map rgb-darker
(map color-name->rgb
(list "red" "orange" "yellow" "green" "blue" "indigo" "violet"))))))
Another solution to 2b.
(define rainbox-colors
(list "red" "orange" "yellow" "green" "blue" "indigo" "violet"))
(apply beside
(map thickly-outlined-circle
(map (lambda (c) (rgb-darker (rgb-darker (color-name->rgb c))))
rainbow-colors)))
How would composition help? (TPS)
(apply beside
(map (o thickly-outlined-circle rgb-darker rgb-darker color-name->rgb)
rainbow-colors))
Do we have a final for this class?
We have an optional SoLA 5, which gives you one last chance to make up any missing LAs (except for the paper-only LAs). It will be online, so you can take it anywhere with Interweb access.
Will I have another chance to make up the tracing LA?
Yes. We will have an in-class tracing quiz each week until one of the following situations happen: (a) everyone has passed or (b) we reach the end of the semester.
Are there any other in-class-only LAs?
Yes. There’s one on diagramming structures in phase 3.
When is the next SoLA?
Week 8, right after spring break.