Next: srfi strings spec select, Previous: srfi strings spec cons, Up: srfi strings spec [Index]
string->list
returns a newly allocated list of the characters
that make up the given string. list->string
returns a newly
allocated string formed from the characters in the list char-list,
which must be a list of characters. string->list
and
list->string
are inverses so far as equal?
is concerned.
An efficient implementation of (compose list->string reverse)
:
(reverse-list->string '(#\a #\B #\c)) => "cBa"
This is a common idiom in the epilog of string–processing loops that
accumulate an answer in a reverse–order list. See also
string-concatenate-reverse
for the “chunked” variant.
This procedure is a simple unparser: it pastes strings together using the delimiter string.
The grammar argument is a symbol that determines how the delimiter
is used, and defaults to infix
. Supported values for
grammar are:
infix
Means an infix or separator grammar: insert the delimiter between list elements. An empty list will produce an empty string; note, however, that parsing an empty string with an infix or separator grammar is ambiguous: is it an empty list, or a list of one element, the empty string?
strict-infix
Means the same as infix
, but will raise an error if given an
empty list.
suffix
Means a suffix or terminator grammar: insert the delimiter after every list element. This grammar has no ambiguities.
prefix
Means a prefix grammar: insert the delimiter before every list element. This grammar has no ambiguities.
The delimiter is the string used to delimit elements; it defaults to a single space.
Examples:
(string-join '("foo" "bar" "baz") ":") ⇒ "foo:bar:baz" (string-join '("foo" "bar" "baz") ":" 'suffix) ⇒ "foo:bar:baz:" ;; Infix grammar is ambiguous wrt empty list vs. empty string, (string-join '() ":") ⇒ "" (string-join '("") ":") ⇒ "" ;; but suffix & prefix grammars are not. (string-join '() ":" 'suffix) ⇒ "" (string-join '("") ":" 'suffix) ⇒ ":"
Next: srfi strings spec select, Previous: srfi strings spec cons, Up: srfi strings spec [Index]