Tcl : nested list

Here is various way to create nested list in tcl. Remember that every thing is a string in Tcl.

% set nestedlist1 { 1 2 { a b c } 3 { d e f } 4 5 }

%set nestedlist2 [list 1 2 [list a b c] 3 [list d e f] 4 5]

%set innerlist1 {a b c}

%set innerlist2 [list d e f]

%set nestedlist3 “1 2 $innerlist1 3 $innerlist2 4 5”

Lindex command can also used to extract an element of nested list.

%lindex $nestedlist1 2 1

b

Try it on tclsh by hand ! Bye …

Leave a Reply

Your email address will not be published. Required fields are marked *