string->list(3scm)
π string->list β convert between strings and lists β¨
okay bestie, this is string->list(3scm) straight out of the Scheme Programmer's Manual, and it's literally the glow-up page for two little procedures that turn strings into lists and lists into strings. no cap, it's giving "tiny but essential" π
πΈ LIBRARY πΈ
where do u import these cuties from? pick ur era:
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
β¨ SYNOPSIS β¨
the whole vibe, verbatim:
(string->list string)
(string->list string start) ;R7RS
(string->list string start end) ;R7RS
(list->string list)
π¦ DESCRIPTION π¦
so string->list hands u back a newly allocated list made of all the characters chillin' inside the string u gave it. fresh list, brand new, no sharing, slay π
and list->string is the reverse glow-up: it returns a newly allocated string built out of the characters in list.
these two are inverses of each other as far as equal?(3string) is concerned, and they preserve the order of the characters. so like, no shuffling, no surprises, the order stays exactly where it was π«Ά
R7RS β extra detail for the R7RS girlies: string->list returns a newly allocated list of the characters of string between start (inclusive) and end (exclusive). classic half-open interval behavior, we love to see it β
π§ IMPLEMENTATION NOTES π§
plot twist: some implementations have a single empty string object. like one (1) empty string for everybody. see make-string(3scm) for the tea π
π RETURN VALUES π
both of these return a single value, no multiple-value drama:
string->listreturns a list (which is either a pair or the empty list)list->stringreturns a string object
π EXAMPLES π
watch it work, it's iconic:
(string->list "Quux") => (#\Q #\u #\u #\x)
(list->string '(#\f #\o #\o)) => "foo"
π APPLICATION USAGE π
ngl these procedures show up in some highly functional programming styles. that's the whole note. highly functional. very main character energy π₯
π COMPATIBILITY π
the start and end arguments are unique to R7RS β like, they're the R7RS exclusive β¨
the only other difference between implementations is whether the empty string is newly allocated or not (see the implementation notes above, iykyk) π
π 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,listmust be a list of characters andstringmust be a string. like, be serious pls π
R7RS β the assertions described above are errors. implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. yes, catastrophically. dramatic much? π
π«Ά SEE ALSO π«Ά
go read these next, they're besties too:
β STANDARDS β
R4RS, R5RS, R6RS, R7RS β collected them all, infinity gauntlet style π
πΈ HISTORY πΈ
these procedures first appeared in R2RS. they are missing from IEEE Scheme. rip to IEEE Scheme but they're different π
π 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/ π
okay that's the whole page, every last crumb preserved π
and that's a wrap babes β page dated 2022-05-12, brought to u by the scheme-manpages project (source/version realness), string->list(3scm) forever πβ¨
π¦ 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