comma-list ( parts conjunction -- clause-seq )
English natural language transformations

Prev:a10n ( word -- numeronym )
Next:or-markup-example ( classes -- markup )


Vocabulary
english

Inputs and outputs
partsa sequence
conjunctiona string
clause-seqa sequence


Word description
Generate a comma-separated list of things, emplacing conjunction before the last part if there are two or more elements in parts.

Notes
This word attempts to preserve the letter case style of the input.

Examples
USING: english io sequences ; { "a cat" "a peach" "an object" } "or" comma-list concat print
a cat, a peach, or an object


See also
a/an, ?plural-article, a10n, $or-markup-example, or-markup-example

Definition


: comma-list ( parts conjunction -- clause-seq )
[ ", " interleaved ] dip over length dup 3 >=
[ [ 3 > ", " " " ? " " surround ] [ 2 - pick set-nth ] bi ]
[ 2drop ] if ;