EBoard 13: Lists (Section 2)

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

  • Administrative stuff [10 min]
  • About MP4 [10 min]
  • Some notes from the last lab [10 min]
  • Quick notes on the self checks [5 min]
  • Questions and answers [5 min]
  • Lab [35 min]
  • Turn in Lab [5 min]

Administrative stuff

Introductory notes

  • Warning! It’s Friday the 13th (class).
  • Today is our start of three days of exploring lists in Racket.
  • I am out of Otter.ai minutes, so there is no Otter transcription/summary for today’s class. Sorry!
  • I will be out of town Tuesday through Friday next week, attending the annual ACM Technical Symposium in Computer Science Education.
    • I’ll check Teams Messages from time to time.
    • You will have subs on Wednesday and Friday.
  • Many people struggled on the Documentation Quiz/LA. The mentors will go over it on Sunday/Tuesday.
  • Many people struggled on MP3. I count 18 I’s and 5 missing assignments.
    • Please read the guidance for R and try to start by shooting for R. (It’s easier on some MPs than others.)
    • Please reach out for help!
    • Please use the evening tutors.
    • No charge for redoing the I’s on MP3.
  • I have posted a redo for MP3.

Upcoming activities

Scholarly

  • Tuesday, 25 February 2025, Noon–12:50 p.m., PDR 224C (White Dining Room). CS Table: TBD
  • Thursday, 27 February 2025, 11:00 a.m.–Noon, JRC 101. Scholars’ Convocation: Emily Wilson: Retranslating the Classics

Artistic

  • Friday, 21 February 2025, 7:00 p.m., The Wall The Neverland Players
  • Saturday, 22 February 2025, 2:00 p.m., The Wall The Neverland Players
  • Saturday, 22 February 2025, 7:00 p.m., The Wall The Neverland Players
  • Sunday, 23 February 2025, 2:00 p.m., The Wall The Neverland Players

Multicultural

  • Friday, 21 February 2025, 4:00–5:00 p.m., HSSC N1170 (Global Living Room). Middle of Everywhere: Beyond the War: Ukraine on the Cultural Front

Peer

Musical, theatric, sporting, and academic events involving this section’s students are welcome.

  • Thursday night–Sunday night, The Natatorium. Swimming Conference Meet.
  • Friday, 21 February 2025, 8:00 p.m., Gardner Lounge. Awesome opening act for Random band

Wellness

  • Friday, 21 February 2025, 9:00 p.m., Noyce Elbow. Nerf at Noyce.
  • Tuesday, 25 February 2025, 12:15–12:50 p.m., GCMoA. Yoga in the Museum.
  • Tuesday, 25 February 2025, 4:30–6:30 p.m., BRAC P103 (Multipurpose Dance Studio). Wellness Yoga.

Misc

  • Sunday, 23 February 2025, 7:30–8:30 p.m., Science 3819. Mentor Session
  • Tuesday, 25 February 2025, 7:00–8:00 p.m., Science 3820. Mentor Session

Other good things

These do not earn tokens, but are worth your consideration.

Upcoming work

Friday PSA

  • You are awesome. Please take care of yourselves.
  • Moderation in everything.
  • Consent is essential, but not sufficient.

Mini-Project 4

Brand new! Please keep me posted on confusing or long parts.

Summary: Like mini-project 3, but with conditionals.

Also:

  • Fewer problems: Six primary procedures, two “go from color to image” procedures, and one freestyle.
  • Less math. (There is a circle problem; ask me if you have trouble understanding the circle formula.)

Notes from conditionals lab

No-parameter versions

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

Vocabulary: zero?

(define is-even?
  (lambda (val)
    (= (remainder val 2) 0)))

This is a bit hard to read because the 0 parameter to = is way off to the right.

We can make it slightly clearer this way.

(define is-even?
  (lambda (val)
    (= 0 (remainder val 2))))

We make it even clearer using the amazing zero? predicate.

(define is-even?
  (lambda (val)
    (zero? (remainder val 2))))

Reminder: Cut and compose

Can we make that even more concise with cut and composition? (TPS)

(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: When you’ve written a procedure, USE IT! (Don’t copy the body.)

Median of three

(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.

We could also ignore conditionals.

(define median-of-three
  (lambda (x y z)
    (- (+ x y z)
       (min x y z)
       (max x y z))))

A note on the self-checks

One solution to 2b.

(define rainbow-colors
  (list "red" "orange" "yellow" "green" "blue" "indigo" "violet"))
(define dark-circles
  (apply beside
         (map thickly-outlined-circle
              (map rgb-darker
                   (map rgb-darker
                        (map color-name->rgb 
                             rainbow-colors))))))

Another solution to 2b.

(apply beside
       (map thickly-outlined-circle
            (map (lambda (c) (rgb-darker (rgb-darker (color-name->rgb c))))
                 rainbow-colors)))
(apply beside
       (map (lambda (c) (thickly-outlined-circle
                         (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))

Q&A

Administrative

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.

Lab