chickadee » srfi-13 » string-join

(string-join string-list [delimiter grammar]) -> stringprocedure

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.

  • '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 " ".

(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) => ":"