Version 1 of lset

Updated 2001-11-19 11:42:38

http://www.purl.org/tcl/home/man/tcl8.4/TclCmd/lset.htm will eventually have the formal man page for lset.


Kevin Kenny writes on news:comp.lang.tcl.announce :

 Subject: TIP's 22, 33, 45 - extended [list] functionality - now final.
 Date: 18 Nov 2001 11:30:33 -0800
 Message-ID: <[email protected]>

Jeff Hobbs today committed to the CVS HEAD at Sourceforge the changes described in TIP's 22 (Multiple Index Arguments to lindex), 33 (Add 'lset' Command to Assign to List Elements), and 45 (Empty index lists for lindex and lset)

These changes augment the lindex command so that it can extract elements from sublists, for example:

    [lindex {{a b c} {d e f} {g h i}} 1 1] => e

They also implement an lset command that may be used to change individual elements within lists and sublists. Taken together, these commands can be used to treat lists as if they were linear arrays. For instance, the following procedure might be used to reverse the order of elements in a list.

    proc reverse { list } {
        set i 0
        set j [expr { [llength $list] - 1 }]
        while { $j > $i } {
            set temp [lindex $list $i]
            lset list $i [lindex $list $j]
            lset list $j $temp
            incr i
            incr j -1
        }
        return $list
    }

Updated documentation for the commands is available in the 'doc/' subdirectory in the source tree. The original proposals may be found at

    http://www.purl.org/tcl/tip/22.htm 
    http://www.purl.org/tcl/tip/33.htm 
    http://www.purl.org/tcl/tip/45.htm