other versions
- wheezy 8.4.19-5
conflicting packages
| lset(3tcl) | Tcl Built-In Commands | lset(3tcl) |
NAME¶
lset - Change an element in a listSYNOPSIS¶
lset varName ?index...? newValueDESCRIPTION¶
The lset command accepts a parameter, varName, which it interprets as the name of a variable containing a Tcl list. It also accepts zero or more indices into the list. The indices may be presented either consecutively on the command line, or grouped in a Tcl list and presented as a single argument. Finally, it accepts a new value for an element of varName. If no indices are presented, the command takes the form:lset varName newValue
lset varName {} newValue
lset a 1 2 newValue
lset a {1 2} newValue
EXAMPLES¶
In each of these examples, the initial value of x is:set x [list [list a b c] [list d e f] [list g h i]]
=> {a b c} {d e f} {g h i}
lset x {j k l} => j k l
lset x {} {j k l} => j k l
lset x 0 j => j {d e f} {g h i}
lset x 2 j => {a b c} {d e f} j
lset x end j => {a b c} {d e f} j
lset x end-1 j => {a b c} j {g h i}
lset x 2 1 j => {a b c} {d e f} {g j i}
lset x {2 1} j => {a b c} {d e f} {g j i}
lset x {2 3} j => list index out of range
set x [list [list [list a b] [list c d]] \
[list [list e f] [list g h]]]
=> {{a b} {c d}} {{e f} {g h}}
lset x 1 1 0 j => {{a b} {c d}} {{e f} {j h}}
lset x {1 1 0} j => {{a b} {c d}} {{e f} {j h}}
SEE ALSO¶
list(3tcl), lappend(3tcl), lindex(3tcl), linsert(3tcl), llength(3tcl), lsearch(3tcl), lsort(3tcl), lrange(3tcl), lreplace(3tcl)KEYWORDS¶
element, index, list, replace, set| 8.4 | Tcl |