Joining two lists

Now that we have seen how to make a list we will explore combining lists. To accomplish this, Tcl provides the concat command. The syntax is as follows:

	concat value1 value2 …

How to do it…

In the following example, we will concatenate a set of lists containing single characters. Return values from the commands are provided for clarity. Enter the following command:


% concat {a b c} {1 2 3}
a b c 1 2 3

How it works…

The concat command joins each of its arguments together with spaces after first trimming all leading and trailing whitespace, and in the case of a list, the results will be flattened. Although this command will concatenate any arguments provided, we will be focusing on its usage as it applies to the list elements. To ...

Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.