hashtable-entries(3scm)
π 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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2023 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms