chickadee » srfi-135 » textual-join

(textual-join textual-list [delimiter grammar]) → textprocedure

This procedure is a simple unparser; it pastes texts together using the delimiter text.

textual-list is a list of texts and/or strings. delimiter is a text or 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 text.
  • strict-infix means the same as infix if the textual-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 text used to delimit elements; it defaults to a single space " ".

(textual-join '("foo" "bar" "baz")) ⇒ «foo bar baz»
(textual-join '("foo" "bar" "baz") "") ⇒ «foobarbaz»
(textual-join '("foo" "bar" "baz") «:») ⇒ «foo:bar:baz»
(textual-join '("foo" "bar" "baz") ":" 'suffix) ⇒ «foo:bar:baz:»

;; Infix grammar is ambiguous wrt empty list vs. empty text:
(textual-join '()   ":") ⇒ «»
(textual-join '("") ":") ⇒ «»

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