EBoard 24 (Section 1): Dictionaries, Maps, and Hash Tables

Approximate overview

  • Administrative stuff [~5 min]
  • Racket stuff [~5 min]
  • Questions [~5 min]
  • Lab [~60 min]

Administrivia

Introductory notes

  • Welcome back from break!
  • Our graders finished much of the MP stuff, but not all of it.
  • As soon as the MP2 redo is graded, I’ll distribute grades again.

Class mask policy

  • We will continue to wear masks until at least the next course survey.

Reminders

  • Please say your name when you ask or answer a question (even if I’ve just called you by name).
  • Evening tutors are available 7–10 p.m. Sunday through Thursday as well as 3–5 p.m. on Sunday.
  • Mentor sessions are Monday 8–9 p.m. Wednesday, 8–9 p.m., Sunday 4–5 p.m.

Upcoming work

  • Reading for today due ASAP.
  • Wednesday’s reading due Tuesday at 10:00 p.m.
  • Today’s lab due Tuesday at 10:30 p.m.
  • Quiz 9 distributed Friday at 8am: Vectors.
  • MP 5 due Thursday at 10:30 p.m.
    • Autograder and submission form should be live tonight.
  • SoLA 3 next week.

Upcoming Token-Generating Activities

  • Thursday 11am, Convocation
  • Thursday 1pm, Baseball vs. Cornell College
  • Thursday 3:30pm, Baseball vs. Cornell College
  • Saturday 1pm, Softball vs. University of Wisconsin Stevens Point
  • Saturday 3pm, Softball vs. University of Wisconsin Stevens Point

Other Upcoming Activities

Racket/Lab Stuff

As I reviewed the reading responses on vectors, I noted that there was some confusion on vector-set!. The vector-set! procedure, like most procedures that end in an exclamation point, returns nothing (or at least nothing you see). You call it only for the side effect of changing the vector.

You’ll discover that hash-set! and hash-remove! also don’t seem to return anything.

Note: In reality, these procedures return a special value, #<void>. Racket generally doesn’t display void values, unless they appear nested in other values.

Questions

Reading questions

Can you explain the difference between immutable and mutable hash tables?

You’ll find that it’s much like vectors: You can add and change values in mutable hash tables, but you can’t do so in immutable hash tables. We’ll explore those differences in lab.

Can you have multiple authors for a single book?

You could choose to associate a list of authors with a title, rather than a single author.

For example,

  (hash-set! book-authors "Goodnight Moon" 
                          '("Margaret Wise Brown"
                            "Clement Hurd"))

Can you keep doing that?

Sure.

Other issues

Are office hours still online?

Yup. The surge of the new Omicron variant suggests they should be.

Can I meet with you outside of office hours?

Certainly. Propose a time using the Outlook/Teams scheduler.

Will there be an opportunity for a second redo of MP1 and MP2?

Yup. It will cost two tokens to do a second redo.

Have you updated tokens recently?

I will tonight. If all goes well, they’ll also be part of the grade sheet. (I need to update the grade sheet software to include them.)

Lab

Preparatory notes

  • Make sure to include your section number and the semester.
  • If I say “Sam said I can stop here”, please make that location clear in your code.
  • Please use your full names.
  • Please reindent before submitting.

Preparation

  • Have the normal start-of-lab discussion.
  • Read over the code!
  • Save the file as hash-tables.rkt

During Lab

Why doesn’t hash-remove! issue an error when the key is not present?

Because it still achieves your goal: Afterwards, the key is not present.

Note: hash-set! changes a mutable hash table, while hash-set returns a new immutable hash table. (Similar for hash-remove! and hash-remove.)

For the Jane Eyre problem, use something like

(define sample-words
  (file->words "hash-tables.rkt"))

Note: If you look at the value returned by hash-set! (or almost any exclamation procedure, you’ll find that it’s #void).

Wrapup

Please finish the lab on your own. (Question 7 will be important for future activities.) You can work with your partner or you can do it separately.