hashtable-keys(3scm)

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

✨ hashtable-keys β€” a manual page, but make it cute ✨

Hey bestie πŸ’– welcome to hashtable-keys(3scm), straight out of the Scheme Programmer's Manual. Yes we're reading a manpage together, yes it's a vibe, no you can't leave yet 🫢

🌸 NAME 🌸

hashtable-keys β€” get the keys from a hashtable πŸ”‘

πŸŽ€ LIBRARY πŸŽ€

Same deal as always, you import it from whichever flavour of the standard you're living in rn:

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

πŸ¦‹ SYNOPSIS πŸ¦‹

(hashtable-keys hashtable)

That's it. One argument. One icon. πŸ‘‘

πŸ’… DESCRIPTION πŸ’…

Okay so real talk β€” this procedure hands you back a vector of all the keys chilling inside hashtable. Every single one. The whole squad. πŸŽ‰

The way that the ordering is unspecified though β€” like, do not come for me asking what order they come out in, because the answer is "whatever, it's a mystery." πŸ™ˆ Don't rely on it, don't build your app on it, just sort it yourself if you care, iykyk.

⭐ RETURN VALUES ⭐

Returns a single value. That value? A vector. One (1) vector. That's the whole personality. πŸ’œ

πŸ”₯ EXAMPLES πŸ”₯

Here's the code, no cap, exactly as written:

(do ((ht (make-eqv-hashtable))
     (n 10)
     (i 0 (+ i 1)))
    ((> i n)
     (vector-sort < (hashtable-keys ht)))
  (do ((j 0 (+ j 1)))
      ((> j n))
    (hashtable-set! ht (* i j) #t)))
    => #(0 1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20
        21 24 25 27 28 30 32 35 36 40 42 45 48 49 50
        54 56 60 63 64 70 72 80 81 90 100)

Look at that output ate πŸ’― β€” it's literally the multiplication-table keys all sorted because the example called vector-sort, not because the procedure promised you anything about ordering. Reminder from your girl: order is unspecified. πŸ””

πŸ› COMPATIBILITY πŸ›

This one is unique to R6RS β€” main character energy, no shared universe. Similar procedures do exist elsewhere though: SRFI-69 and SRFI-125 got their own versions. So if you're porting, bestie, check your imports. 🧚

πŸ’€ ERRORS πŸ’€

Yeah it can raise exceptions, and here's the condition type to catch:

  • &assertion (R6RS) β€” thrown when you passed the wrong number of arguments, or an argument was outside its domain. Specifically: hashtable has to be a hashtable. Like, babe, it's in the name. 😭 Pass it something that isn't one and it's over.

🌈 SEE ALSO 🌈

πŸ‘‘ STANDARDS πŸ‘‘

R6RS ⭐ β€” that's the one, that's the source.

πŸ“ HISTORY πŸ“

This procedure first appeared in R6RS. But plot twist: an equivalent procedure already existed in SRFI-69, and it was going by the name hash-table-keys the whole time. Not me finding out my fave has an older sibling πŸ’€

🌸 AUTHORS 🌸

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More info lives at https://github.com/schemedoc/manpages/ β€” go snoop, it's giving documentation royalty ✨


and that's the whole page bestie, mwah πŸ’‹ β€” brought to you by the version tagged 2023-01-22, hashtable-keys(3scm) edition. Periodt. πŸ’…

πŸ“¦ where this page comes from