% join {a b c} " and " a and b and c % join {a b c} "" abc
RS A typical application is to process a text that consists of several lines:
Matrices are a frequent application for nested lists. Here's a simple matrix summer that uses join twice: once for concatenating the rows; then for putting + signs in between so expr has something to parse:
foreach line [split $input \n] { # do something with line, produce output lappend outlines $out } set result [join $outlines \n]Another is to flatten out one level of embedded lists:
% join {1 {2 {3 4}} 5} 1 2 {3 4} 5Lars H: As of Tcl 8.5, a more kosher way of doing that would be
concat {*}$nestedListe.g. (yes, it looks silly)
% concat {*}{1 {2 {3 4}} 5} 1 2 {3 4} 5The difference is that concat can return a list (something internally stored as a list), whereas join always returns a string, resulting in shimmering.
Matrices are a frequent application for nested lists. Here's a simple matrix summer that uses join twice: once for concatenating the rows; then for putting + signs in between so expr has something to parse:
proc matsum matrix {expr [join [join $matrix] +]}