chickadee » srfi-152 » string-join

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

This procedure is a simple unparser; it pastes strings together using the delimiter string.

string-list is a list of strings. delimiter is a string. The grammar argument is a symbol that determines how the delimiter is used, and defaults to infix.

It is an error for grammar to be any symbol other than these four:

  • infix means an infix or separator grammar: insert the delimiter between list elements. An empty list will produce an empty string.
  • strict-infix means the same as infix if the string-list is non-empty, but will signal an error if given an empty list. (This avoids an ambiguity shown in the examples below.)
  • suffix means a suffix or terminator grammar: insert the delimiter after every list element.
  • prefix means a prefix grammar: insert the delimiter before every list element.

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") "") ⇒ "foobarbaz"
(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 '("") ":") ⇒ ""

;; Suffix and prefix grammars are not:
(string-join '()   ":" 'suffix)) ⇒ ""
(string-join '("") ":" 'suffix)) ⇒ ":"