Reversing elements
Again, to maintain the dynamics of a list, it may be necessary to reverse the elements. To accomplish this, Tcl provides the lreverse
command. The syntax is as follows:
lreverse list
How to do it…
In the following example, we will use the lreverse
command to reverse the elements in our list. Return values from the commands are provided for clarity. Enter the following command:
% lreverse {a b c d e} e d c b a
How it works…
The lreverse
command accepts a list and returns a list containing the elements in reverse order.