Approximate overview
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. You call it only for the side effect of changing the vector.
You’ll discover that hash-set! and hash-remove! also don’t
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.
> sample
'#hash()
> (hash-set! sample 'tutors '(Paul Micah))
> sample
'#hash((tutors . (Paul Micah)))
> (list (hash-set! sample 'tutors 'other))
'(#<void>)
Using the return value from hash-set! or anything similar is generally
a bad idea.
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"))
Is there a way to look up keys by value?
Um … I don’t think there’s a built-in procedure to do that, but you can iterate all of the keys, find the values, and …
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 so.
Have you updated tokens recently?
I will tonight. If all goes well, they’ll also be part of the grade sheet.
hash-tables.rktNote: hash-set and hash-remove (no exclamation points) do not modify
their parameters; rather, they return new hash tables.
Note: '#((key1 . value1) (key2 . value2)) makes an immutable hash
table while (make-hash ...) makes a mutable hash table.
E6: You can use (hash-has-key? hash key) to determine if a hash table
has a particular key.