bytevector->string(3scm)
β¨ bytevector->string β the transcode-a-bytevector-to-a-string glow-up β¨
okay so real quick, this page lives in the Scheme Programmer's Manual (yes, bytevector->string(3scm), that one π
) and it's genuinely one of the most useful little guys in the whole I/O lineup. let's get into it π«Ά
π LIBRARY π
import it from either of these bad boys, depending on your vibe:
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
like, both work. pick your fighter πΈ
π SYNOPSIS π
(bytevector->string bytevector transcoder)
two args, no drama. bytevector and transcoder. that's the whole signature, bestie β¨
π¦ DESCRIPTION π¦
so what it does is: it takes bytevector and transcodes it according to the input direction of transcoder, and hands you back the resulting string. that's it. that's the whole personality π
(and yes, "input direction" is doing real work in that sentence β it's the input side of the transcoder that's in charge here, not the output side. iykyk π)
π RETURN VALUES π
Returns a single value: a string. one value. not a list, not a couple of things, just the string. iconic behavior, honestly π
β EXAMPLES β
ok these are so clean, look:
(bytevector->string #vu8(81 117 117 120) (native-transcoder))
=> "Quux"
literally just bytes in, "Quux" out. ate. π₯
and then the spicy one where things go sideways:
(bytevector->string #vu8(#xff)
(make-transcoder (utf-8-codec)
(native-eol-style)
(error-handling-mode raise)))
=> &i/o-decoding
yep β #xff is not valid UTF-8 and you said raise, so it raises. that's the deal you made π (more on that below π)
πΈ APPLICATION USAGE πΈ
this procedure is the more general, more flexible alternative to utf8->string(3scm). like, utf8->string is cool but this one lets you pick the transcoder, so it's giving main character energy π
π COMPATIBILITY π
this procedure is unique to R6RS. periodt. if you're on something else, sorry bestie π
π¨ ERRORS π¨
it can raise exceptions with these condition types, so know them before you get humbled:
&assertion(R6RS) β you passed the wrong number of arguments, or an argument was outside its domain. classic. π&i/o-decoding(R6RS) β a sequence of bytes showed up that could not be translated into a string, and the transcoder's error-handling-mode israise. like if you'd set it to something chiller, it wouldn't be raising at you. π
π§ SEE ALSO π§
go check these out, they're all in the same friend group:
string->bytevctor(3scm)utf8->string(3scm)open-bytevector-output-port(3scm)make-transcoder(3scm)
(and yeah, string->bytevctor is spelled exactly like that on the page β not me, blame the original π copy it as-is if you're grepping for it!)
π STANDARDS π
R6RS. that's the whole section. slay. β¨
π HISTORY π
This procedure first appeared in R6RS, as part of the redesigned I/O system. so it's not ancient lore, it's a glow-up baby π±
π 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/.
ok tiny recap so it sticks: bytevector + transcoder (input direction) β one string. watch out for&assertionand&i/o-decoding. and don't forget it's R6RS-only, mwah π
that's the whole page, bestie β go transcode something π
later, and remember: it's bytevector->string(3scm), from the Scheme Programmer's Manual, dated 2020-05-14. π¦
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms