- have access to some of the enhancements
- be able to write code that will be forward compatible and won't need rewriting to gain performance or syntax improvements when run on post-8.3 Tcl
- have tools to help us back-port useful stuff to 8.3 (caveat emptor!)
if { $tcl_version < 8.4 } { # the code below goes here }Here t'is:
# Hide the default lindex command rename lindex _lindex # Define the new command proc lindex { theList args } { switch -exact [llength $args] { 0 { # lindex l (get l) return $theList } 1 { # lindex l i (get i'th element of l) # lindex l {} (get l) # lindex l {i j k} (get the k'th element of the j'th element of the i'th element of l) set indexList [_lindex $args 0] switch -exact [llength $indexList] { 0 { # lindex l {} return $theList } 1 { # lindex l i # lindex l {i} return [_lindex $theList $indexList] } default { # lindex l {i j k} (get the k'th element of the j'th element of the i'th element of l) set index [_lindex $indexList 0] set subList [_lindex $theList $index] return [lindex $subList [lrange $indexList 1 end]] } } } default { # lindex l i j k set indexList $args set index [_lindex $indexList 0] set subList [_lindex $theList $index] return [lindex $subList [lrange $indexList 1 end]] } } return $theList }
See Also: lset forward compatibility, sugar for Tcl/Tk 8.3