hashtable-copy(3scm)
π hashtable-copy β like, a whole manual page, bestie
okay so this is hashtable-copy from the Scheme Programmer's Manual (yes the 3scm one, you're in the right place π), and honestly? it's giving "tiny procedure, big slay."
β¨ NAME β¨
hashtable-copy β copy a hashtable. that's it. that's the whole vibe. π«Ά
π LIBRARY π
bestie you gotta import it first, no cap:
(import (rnrs)) ;R6RS
(import (rnrs hashtables)) ;R6RS
πΈ SYNOPSIS πΈ
the two forms, exactly as written, don't @ me:
(hashtable-copy hashtable)
(hashtable-copy hashtable mutable)
π DESCRIPTION π
so basically it returns a copy of hashtable. like a clone. a twin. a doppelgΓ€nger but make it functional. π
now here's the tea π β if the mutable argument is provided and it's true, then the returned hashtable is mutable. otherwise? it's immutable. locked. frozen. no takebacks. π
π RETURN VALUES π
returns a single value: a hashtable. one (1) hashtable. that's the whole return. π
π EXAMPLES π
okay this example is actually iconic, watch:
(define (alist->eqv-hashtable alist)
(let ((ht (make-eqv-hashtable)))
(do ((alist alist (cdr alist)))
((null? alist)
(hashtable-copy ht))
(hashtable-set! ht (caar alist) (cdar alist)))))
like, it builds up the hashtable then copies it on the way out. main character energy honestly.
and then:
(hashtable-entries
(alist->eqv-hashtable '((0 . zero) (1 . one) (2 . three))))
=> #(0 1 2)
#(zero one three)
see how the entries come back? chef's kiss. π₯ (yes, (2 . three) is in the original, it's not a typo, leave it alone π)
π§ RATIONALE π§
why even allow immutability? because allowing the hashtable to be immutable lets implementations create an optimized representation for the hashtable. so it's not just cute, it's efficient. iykyk. β¨
π¦ COMPATIBILITY π¦
this procedure is unique to R6RS. so if you're on something else? not me finding out the hard way π
π ERRORS π
this procedure can raise exceptions with the following condition types:
&assertion(R6RS) β the wrong number of arguments was passed, or an argument was outside its domain. in particular, hashtable must be a hashtable. like, bestie, it has to actually BE a hashtable, okay?? π«
π SEE ALSO π
make-hashtable(3scm) β go read that one too, it's the whole origin story π§
β STANDARDS β
R6RS. periodt. π
π°οΈ HISTORY π°οΈ
this procedure first appeared in R6RS, but a similar procedure was also present in SRFI-69. so it's got lore. π
π 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/. π«Ά
and that's the page!! mwah π β this was hashtable-copy(3scm), dated 2023-01-22, from the Scheme Programmer's Manual (that's the source/version right there, don't say i never told you). go copy some hashtables, bestie, you got this π¦π
π¦ 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