hashtable-set!(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’… hashtable-set!(3scm) β€” the one where you change an association in a hashtable

okay so bestie, welcome to the Scheme Programmer's Manual ✨ and honestly? this page is short and sweet and it's gonna change your whole day, no cap.


🌸 NAME 🌸

hashtable-set! β€” change an association in a hashtable πŸŽ€


πŸ“š LIBRARY πŸ“š

import it one of these ways, iykyk:

(import (rnrs))                     ;R6RS
(import (rnrs hashtables))          ;R6RS

✨ SYNOPSIS ✨

(hashtable-set! hashtable key obj)

that's it. three arguments. main character energy fr fr πŸ’–


πŸ’– DESCRIPTION πŸ’–

so what it does is it changes hashtable so that it associates key with obj β€” like, it either adds a brand new association, or it replaces whatever association was already there for key. it's giving "out with the old, in with the new" 🌈 and it literally does not care which one it's doing, it just handles it πŸ’…


🧚 IMPLEMENTATION NOTES 🧚

okay so lowkey this is important: calling this procedure can trigger growth of the hashtable, and when that happens it can require all keys to be hashed again 😭 like the whole squad gets re-hashed. just so you know. 🫢


⭐ RETURN VALUES ⭐

returns unspecified values. that's it. nothing to see here, no cool little result to show off, it's just vibes πŸ¦‹


πŸ“ EXAMPLES πŸ“

here's the whole cute little scenario:

(define ht (make-eq-hashtable))
(hashtable-set! ht 'foo 'bar)
(hashtable-ref ht 'foo #f)   =>  bar

look at that. bar came back. ate. πŸ‘‘


πŸ”₯ COMPATIBILITY πŸ”₯

this procedure is unique to R6RS β€” like, it's its thing. but similar procedures do exist in SRFI-69 and SRFI-125, so if you're slumming it in a different SRFI you're not totally stranded, bestie πŸ’€


πŸ™ˆ ERRORS πŸ™ˆ

this procedure can raise exceptions with these condition types:

  • &assertion (R6RS) β€” this one hits when you passed the wrong number of arguments, or when an argument was outside its domain. specifically: hashtable should actually be a hashtable, and key should be in the domain of the hashtable's hash and equal functions. so like. use it right. 😭

πŸ¦‹ SEE ALSO πŸ¦‹

(the holy trinity honestly πŸŽ€)


πŸ‘‘ STANDARDS πŸ‘‘

R6RS. periodt. πŸ’œ


🌈 HISTORY 🌈

this procedure first appeared in R6RS. and fun fact: an equivalent procedure already existed in SRFI-69 under the name hash-table-set!. so it's not even a new idea, it just got a glow-up ✨


🧚 AUTHORS 🧚

this page is part of the scheme-manpages project. it includes materials from the RnRS documents. more information can be found at https://github.com/schemedoc/manpages/ 🫢


no cap, that's the whole page. go forth and set some keys, bestie πŸ’…

okay and finally, the cute little sign-off: this gem dropped on 2023-01-22, straight from the Scheme Programmer's Manual, and it's hashtable-set!(3scm) through and through πŸ’–πŸŽ€βœ¨

πŸ“¦ where this page comes from