get-string-n!(3scm)
π get-string-n! β read characters into a string π
okay so real talk, this page is from the Scheme Programmer's Manual (yes, the 3scm section, we love a niche corner of the manual), and it's about one very specific little procedure. she's niche. she's specific. she's get-string-n!. let's get into it π
β¨ LIBRARY β¨
bestie you gotta import her first, and she lives in two spots depending on your vibe:
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
β¨ SYNOPSIS β¨
the whole entire shape of her, no cap:
(get-string-n! textual-port string start count)
πΈ DESCRIPTION πΈ
so what she does is read from textual-input-port the exact same way get-string-n does β same energy, same manners, she's just the ! version (iykyk, the bang means she's mutating your string, she's writing into it, main character behavior π
).
here's the breakdown, and it's literally three whole scenarios:
- if
countcharacters are available before an end of file, they get written into string starting at index start, andcountis returned. slay, full read, ate. - if fewer characters are available before an end of file, but one or more can still be read, those characters get written into string starting at index start, and the number of characters actually read is returned as an exact integer object. flexible queen π¦
- if no characters can be read before an end of file, you get the end-of-file object back, and the end-of-file condition is consumed. that's it, that's the whole thing π
β RETURN VALUES β
she returns a single value, periodt. either an exact positive integer object, or the end of file object. no surprises, no extras, one value, we respect a monogamous return.
π₯ EXAMPLES π₯
here's her in her natural habitat, reading /etc/hostname like the icon she is:
(define s (make-string 10 #\space))
(call-with-port (open-input-file "/etc/hostname")
(lambda (p)
(get-string-n! p s 0 10)))
=> 9
s => "darkstar"
see how she returned 9? that's the actual count read, and s came out as "darkstar". the way that just works ππ
π§ APPLICATION USAGE π§
real talk: "Application usage is rare in practice." that's the whole section. she's a little niche girly. not every procedure gets invited to the party and that's okay π
π COMPATIBILITY π
"This procedure is unique to R6RS." so likeβ¦ if you're on some other Scheme, don't come for her, she's an R6RS exclusive π β¨
π ERRORS π
she can raise exceptions, and here's the full list of condition types, no gatekeeping:
&assertion(R6RS) β the wrong number of arguments was passed, or an argument was outside its domain. specifically, lowkey important: start and count must be exact, non-negative integer objects, and string must be a string with at leaststart+countcharacters. get that math wrong and she WILL yell at you π€&i/o-read(R6RS) β a read error occurred during an I/O operation. sad girl hours π&i/o-decoding(R6RS) β the textual-input-port is associated with a transcoder in theraiseerror handling mode and an invalid byte sequence was encountered. that's a<red>whole situation</red>, okay, be careful π
π SEE ALSO π
go read her cousins too, they're all icons:
π STANDARDS π
R6RS. that's it. that's the standard. π«Ά
β HISTORY β
"This procedure first appeared in R6RS as part of the reworked I/O system." so she's a glow-up baby, born in the big I/O redesign. we stan a rebrand that actually slaps β¨
π AUTHORS π
this page is part of the scheme-manpages project β it includes materials from the RnRS documents, and you can find more info at https://github.com/schemedoc/manpages/. give them a follow, they're doing the lord's work π
and that's the whole page bestie!! π¦ this version is from the 2023-07-23 release of the scheme-manpages project (source: the RnRS documents, obvi) β go forth and read some characters into a string, and remember: start and count must be exact non-negative integers. start+count math or it's a vibe check fail π
πΈπ
π¦ 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