Next: , Previous: , Up: strings   [Index]


25.15 List and string conversion

Function: %string->list* str start past
Macro: string->list* S

Return a newly allocated list of the characters that make up the given substring. This is an extension of the string->list function that adds support for substrings.

Function: %reverse-string->list str start past
Macro: reverse-string->list S

Like %string->list* but reverses the order of the characters from the substring.

Function: reverse-list->string char-list

Reverse the given list of characters, then compose a string with the result.

(reverse-list->string '(#\a #\B #\c))
⇒ "cBa"
Function: %string-tokenize token-set str start past
Function: %string-tokenise token-set str start past
Macro: string-tokenize S token-set
Macro: string-tokenise S token-set

Split the selected substring into a list of strings, where each string is a maximal, non–empty, contiguous sequence of characters from the character set token-set.

(string-tokenize "Help make programs run, run, RUN!"
                 (char-set-complement (char-set #\space)
                                      char-set:ascii))
⇒ ("Help" "make" "programs" "run," "run," "RUN!")

This function provides a minimal parsing facility for simple applications. More sophisticated parsers that handle quoting and backslash effects can easily be constructed using regular–expression systems; be careful not to use string-tokenize in contexts where more serious parsing is needed.

Function: string-join string-list
Function: string-join string-list delimiter
Function: string-join string-list delimiter grammar
Function: %string-join string-list delimiter grammar

This procedure is a simple unparser: It pastes strings together using the delimiter string. delimiter defaults to a single white space. grammar 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: Parsing an empty string with an infix 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 '("") ":") ⇒ ""

(string-join '("") "," 'strict-infix) ⇒ ""
(string-join '("") "," 'suffix) ⇒ ","
(string-join '("") "," 'prefix) ⇒ ","

Next: , Previous: , Up: strings   [Index]