string->list(3scm) Scheme Programmer's Manual string->list(3scm)

string->list, list->string - convert between strings and lists

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

(string->list string)
(string->list string start)         ;R7RS
(string->list string start end)     ;R7RS
(list->string list)

The string->list procedure returns a newly allocated list of the characters that make up the given string.

The list->string procedure returns a newly allocated string formed from the characters in list.

These procedures are inverses so far as equal?(3string) is concerned, and preserve the order of the characters.

R7RS
The string->list procedure returns a newly allocated list of the characters of string between start (inclusive) and end (exclusive).

Some implementations have a single empty string object; see make-string(3scm).

Both of these procedures return a single value. The string->list procedure returns a list (a pair or the empty list); the list->string procedure returns a string object.

(string->list "Quux")  =>  (#\Q #\u #\u #\x)
(list->string '(#\f #\o #\o))  =>  "foo"

These procedures can be seen in some highly functional programming styles.

The start and end arguments are unique to R7RS. The only other difference between implementations is whether the empty string is newly allocated or not (see above).

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, list must be a list of characters and string must be a string.
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.
Unsupported characters (R7RS)
It is an error for the list passed to list->string to contain a character which the implementation does not support. 7-bit ASCII (except #\null) must be supported. Any other character is optional and potentially an error (as described above). You can use the full-unicode feature identifier in cond-expand(3scm) to check if all of Unicode 6.0 is supported.

list->vector(3scm), string-append(3scm)

R4RS, R5RS, R6RS, R7RS

These procedures first appeared in R2RS. They are missing from IEEE Scheme.

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

2022-05-12