EBoard 19: Local Bindings (Section 1)

Warning! You are being recorded and transcribed, provided the technology is working correctly.

Approximate optimistic overview

  • Administrative stuff
  • Q&A
  • Lab

Administrative stuff

Introductory notes

  • Have a great break!
  • Just in case it’s not clear, I would much prefer that you all get an S on each LA the first time through. Writing “S” (and, perhaps, a small comment) takes much less effort than correct errors and then grading another LA.
    • But it’s fine if you don’t get them right the first time; it’s simply a sign that you still have some misconceptions.
  • Thanks for all the suggestions on handling SoLAs and struggling students. I’ll let you know some of the changes after break.
  • I’m hoping to have all your grades to you by the end of the first week of break.

Upcoming activities

These are all after break.

Scholarly

Artistic

Multicultural

  • Friday, 28 March 2025, 4:00–5:00 p.m., HSSC N1170 (Global Living Room). Middle of Everywhere: ???

Peer

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

Wellness

  • Tuesday, 26 March 2025, 12:15–12:50 p.m., GCMoA. Yoga in the Museum.
  • Tuesday, 26 March 2025, 4:30–6:30 p.m., BRAC P103 (Multipurpose Dance Studio). Wellness Yoga.
  • Friday, 28 March 2025, 6:00 p.m.–8:00 p.m., Aux Gym. Badminton Club (Smash that bird!)
  • Friday, 28 March 2025, 9:00 p.m., Noyce Elbow. Nerf at Noyce.
  • Saturday, 29 March 2025, 4:00 p.m.–6:00 p.m., Aux Gym. Badminton Club (Smash that bird!)

Misc

  • Sunday, 9 March 2025, 7:30–8:30 p.m., Science 3819. NO Mentor Session
  • Sunday, 23 March 2025, 7:30–8:30 p.m., Science 3819. Mentor Session (I think)
  • Tuesday, 25 March 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

  • Please be moderate.
  • You are awesome! Please remain that way. For yourself. For those who care about you.
  • Consent is essential, but not sufficient.

Questions

Administrative

I seem to have missed a fair number of labs. Can I make them up over break?

My usual policy is “No”. But the world is chaotic, so I’m being a bit more open. You may make up missed labs over break. Teams Message or Email me when you’ve finished each one and I’ll open up a late submission on Gradescope.

I seem to have missed a fair number of reading responses. Can I make them up over break?

See the previous answer.

I seem to have missed a fair number of post-reflections. Can I make them up over break?

See the previous answer (or perhaps the previous previous answer).

I seem to have missed a fair number of pre-reflections. Can I make them up over break?

No.

Will you post more redos for over break?

Yes. Second redos for MPs 1, 2, and 3 are due the Sunday after break.

First redos for MPs 4 and 5 are also due that Sunday.

If I make up a lab, can I stop after ??? minutes and submit whatever I’ve completed.

Yes. ??? minutes is 60 minutes.

My quiz is missing. What’s up with that?

I’ll look during lab.

When will we know how many tokens we’ve used and earned?

You should know. But I’ll be counting during the first week of break.

Reading (Local bindings)

What is the benefit to using let to define a local helper procedure as opposed to defining it outside the main procedure?

The helper procedure may want to use the parameters to the enclosing procedure. This way, we don’t have to pass all of those parameters to the helper.

E.g.,

(define rectangle
  (lambda (left top width height rcolor bg iwidth iheight)
    (let ([helper (lambda (x y)
                    (cond
                      [(some-test x y width height)
                       rcolor]
                      [...]
                      [else
                       bg]))])
      (image-compute helper iwidth iheight))))

We can worry less about name overlaps. For example, instead of stack-and-sequence-helper, we could just use helper.

Why bother naming our helper procedures instead of using anonymous procedures?

Perhaps it avoids repetition. Perhaps it clarifies our code.

It says that a let expression may have multiple bodies. If the let expression only takes the value of the last body, then why would a programmer use multiple bodies in a let expression?

There are some procedures we call for their “side effects”; they change the state of the system. We haven’t encountered any such procedures yet, but we will.

Can we please go over check 3, ratios revisited?

Certainly.

;;; (v2c-ratio str) -> rational?
;;;   str : string
;;; Determine the ratio of vowels to consonants in str
(define v2c-ratio
  (lambda (str)
    (/ (tally vowel? (string->list str))
       (tally consonant? (string->list str)))))

Idea one:

(define v2c-ratio
  (lambda (str)
    (let ([num-vowels (tally vowel? (string->list str))]
          [num-consonants (tally consonant? (string->list str))])
      (/ num-vowels num-consonants))))

Benefit: Potentialy more readable. But doesn’t solve the problem of calling string->list twice.

(define v2c-ratio
  (lambda (str)
    (let ([chars (string->list str)])
      (let ([num-vowels (tally vowel? chars)]
            [num-consonants (tally consonant? chars)])
        (/ num-vowels num-consonants)))))

Benefit: Only convert the list to a string once.

Here’s a less good approach.

(define v2c-ratio
  (lambda (str)
    (let ([count-chars (lambda (pred?)
                         (tally pred? (string->list str)))])
      (/ (count-chars vowel?)
         (count-chars consonant?)))))

If it works, it’s a bit harder to read. But we’re still doing string->list twice. So this neither clarifies (except for Sam) nor speeds things up.

Scheme

Other

Lab