EBoard 24: Dictionaries and hash tables and such. Oh my!

Approximate overview

  • Admin
    • Discussion of HW 6
  • Quick notes from last lab.
  • Lab

Administrative stuff

Introductory notes

  • I did not catch up on other grading. Sorry! I’m not sure when I will.
  • I have no idea whether or not our projection system will work today. (It seems to be)
  • Sam got the order of parameters to hash-map backwards. Or maybe the Racket designers did. In any case, it’s (hash-map hash proc).

Upcoming activities

Events

  • Wednesday at 7pm: Mentor Session
  • Thursday at 4pm: CS Extras on Programming Language
  • Swim meet Saturday at 1pm
  • Football vs. UofC Saturday at 1pm
  • Any one Grinnell Prize event this weekend. See signs around campus.

Other good things

  • Women’s Volleyball tonight at 7:00 p.m.
  • Women’s Basketball tomorrow at 6:00 p.m.
  • Women’s Volleyball Saturday at 11:00 a.m.
  • Women’s Basketball vs. Alumnae Saturday at 4:00 p.m.
  • Men’s Basketball vs. Alumni Saturday at 6:00 p.m.

Upcoming work

Notes on MP6

  • Fun!

Q&A

How do we submit MP5

I’ll get that up soon.

For MP5, do we have to preserve punctuation?

Nah. But if you want to, that would be great.

Quick notes on pairs lab

A list is either

  • The empty list OR
  • A pair whose cdr is a list
    • That is, it’s a pair AND the cdr is a list

We can write a cond for that.

(define listp?
  (lambda (val)
    (cond
      [(null? val)
       #t]
      [(pair? val)
       (listp? (cdr val))]
      [else
       #f])))

Side comment: Standard cond formatting.

We can also make the stucture of listp? match the definition more closely.

(define listp?
  (lambda (val)
    (or (null? val)
        (and (pair? val)
             (listp? (cdr val))))))

Wasn’t that fun?

Side comment: Embrace the ZoB!

Lab

Preparation

  • Make sure that you have the correct lab page.
  • Person closest to the screen is A. Other person is B.
  • Make sure to have the pre-class discussion.
  • Review the procedures in the lab, too.

Notes during class

hash-set and hash-remove (no exclamation points) return new hash tables. There is some conceptual benefit to being able to ensure that the original hash table is not modified.

You can use the new table defined by hash-set or hash-remove by naming it.

(define new-sidekicks (hash-set sidekicks "Eamon" "Sam"))`

The code in problem 4e should read

> (hash-ref (hash-remove! sidekick-protagonists "The Cheat")
            "The Cheat")

What to submit

Up through 6c