hashtable-entries(3scm)

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

πŸ’… hashtable-entries β€” get the entries in the hashtable as two vectors

okay so real talk, this page is hashtable-entries(3scm) from the Scheme Programmer's Manual, and it's honestly such a vibe. it's a tiny little procedure that hands you your whole hashtable on a platter β€” no cap. let's get into it 🫢


✨ NAME ✨

hashtable-entries β€” get the entries in the hashtable as two vectors πŸŽ€


πŸ“š LIBRARY πŸ“š

bestie you gotta import it first, okay? like so:

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

🌸 SYNOPSIS 🌸

(hashtable-entries hashtable)

one procedure, one argument, that's the whole thing. iconic behavior honestly πŸ’…


πŸ’– DESCRIPTION πŸ’–

so you hand it a hashtable, and it gives you back a vector of the keys in that hashtable and a vector of the corresponding values. like, both at once. two vectors. one call. we love efficiency πŸ¦‹


⭐ RETURN VALUES ⭐

it returns two values β€” two vectors of equal length. that's it, that's the return. two vectors, same length, matching up (well… in some matching order, keep reading πŸ‘€). πŸ’œ


πŸŽ€ EXAMPLES πŸŽ€

here's the moment you've been waiting for, the example, she's gorgeous:

(let ((h (make-eqv-hashtable)))
  (hashtable-set! h 1 'one)
  (hashtable-set! h 2 'two)
  (hashtable-set! h 3 'three)
  (hashtable-entries h))
  => #(1 2 3)
     #(one two three)
          ; entries may be in different order
⚠️ ok so peep that comment at the bottom: entries may be in different order. do NOT hardcode your assumptions about ordering, bestie, that's an L waiting to happen 😭

🌈 APPLICATION USAGE 🌈

reach for this when you're iterating over the entries of a hashtable in an indeterminate order, or when you just need all the associated values from a hashtable. like, all of them. at once. slay 🧚


πŸ”₯ RATIONALE πŸ”₯

ok so why does this exist when you could do it other ways? because: if a program needs all entries in a hashtable, this procedure is significantly faster than using hashtable-keys(3scm) together with hashtable-ref(3scm) for each key β€” the reason being it does not need to use the hash and equal functions. efficiency queen πŸ‘‘βœ¨


πŸ¦‹ COMPATIBILITY πŸ¦‹

this procedure is unique to R6RS β€” main character energy, she doesn't exist elsewhere. but if you want an equivalent, you can find one in SRFI-125 under the name hash-table-entries. so like, cousins basically 🫢


πŸ’€ ERRORS πŸ’€

it can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain. πŸ™ˆ

🌟 SEE ALSO 🌟


⭐ STANDARDS ⭐

R6RS β€” periodt.


🧚 HISTORY 🧚

this procedure first appeared in R6RS. that's the whole origin story, no further lore 😌


πŸ‘‘ AUTHORS πŸ‘‘

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


so yeah, that's the whole page πŸ“ this lil writeup is from the scheme-manpages crew, dated 2023-01-22, and that's hashtable-entries(3scm) β€” go forth and grab your vectors, bestie πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from