Tcl中列表定義的方法有以下三種:app
set colorlist1 {red green blue} red green blue set colorlist2 [red1 green1 blue1] invalid command name "red1" set colorlist2 [list red1 green1 blue1] red1 green1 blue1 set colorlist3 [split "red2_gree2_blue2" _] red2 gree2 blue2 set colorlist4 [split red3_green3_blue3 _] red3 green3 blue3 set colorlist5 [split "red4_gree4_blue4" "_"] red4 gree4 blue4
Tcl中列表的命令通常都是對列表的內容取出來再處理,不會對原列表有什麼影響,以下面代碼:spa
lreplace colorlist5 1 1 g4 list doesn't contain element 1 lreplace $colorlist5 1 1 g4 red4 g4 blue4 $colorlist5 invalid command name "red4 gree4 blue4" puts $colorlist5 red4 gree4 blue4
可是有一個lappend命令倒是直接處理列表自己:code
lappend colorlist5 black red4 gree4 blue4 black puts $colorlist5 red4 gree4 blue4 black
固然lappend命令中不象其它命令那樣用「 $colorlist5",而是要用"colorlist5"這樣的形式。索引
對於一個列表,循環索引以下操做:element
Vivado% set lt {a b c} a b c Vivado% for {set i 0} { $i<[llength $lt]} {incr i} { puts [lindex $lt $i] } a b c
更簡單的列表循環索引操做以下:it
Vivado% foreach c $lt { puts $c } a b c