EBoard 19: Local Bindings (Section 2)

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.
    • Notes are good.
  • 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. (Including tokens.)

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

  • You are awesome. Please stay awesome.
  • Moderation.
  • 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.

Will we have the first redos graded soon?

Yes, by the first Friday of spring break.

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)))))

New version

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

We like this because we’re only calling string->list once rather than twice.

The input to the function is a little bit clearer; we don’t have to spend time trying to understand each call to (string->list str) (and to make sure that they’re the same).

Another new version

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

The “count vowel?” is pretty clear, perhaps clearer than (tally vowel? chars).

What does count do? Let’s look

    (count vowel?)
--> (tally vowel? (string->list str))

This has the same problem as the original that it will crash and burn if there are no consonants in the string.

Although we’ve used let, we’re still repeating work because we’re calling string->list twice.

Perhaps another

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

This achieves both efficiency and clarity.

Scheme

Other

Lab