OSDN Git Service

Updated to tcl 8.4.1
[pf3gnuchains/sourceware.git] / tcl / doc / lset.n
1 '\"
2 '\" Copyright (c) 2001 by Kevin B. Kenny.  All rights reserved.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\" 
7 '\" RCS: @(#) $Id$
8 '\" 
9 .so man.macros
10 .TH lset n 8.4 Tcl "Tcl Built-In Commands"
11 .BS
12 '\" Note:  do not modify the .SH NAME line immediately below!
13 .SH NAME
14 lset \- Change an element in a list
15 .SH SYNOPSIS
16 \fBlset \fIvarName ?index...? newValue\fR
17 .BE
18 .SH DESCRIPTION
19 .PP
20 The \fBlset\fP command accepts a parameter, \fIvarName\fP, which
21 it interprets as the name of a variable containing a Tcl list. 
22 It also accepts zero or more \fIindices\fP into
23 the list.  The indices may be presented either consecutively on the
24 command line, or grouped in a
25 Tcl list and presented as a single argument.
26 Finally, it accepts a new value for an element of \fIvarName\fP.
27 .PP
28 If no indices are presented, the command takes the form:
29 .CS
30 lset varName newValue
31 .CE
32 or
33 .CS
34 lset varName {} newValue
35 .CE
36 In this case, \fInewValue\fP replaces the old value of the variable
37 \fIvarName\fP.
38 .PP
39 When presented with a single index, the \fBlset\fR command
40 treats the content of the \fIvarBane\fR variable as a Tcl list.
41 It addresses the \fIindex\fR'th element in it 
42 (0 refers to the first element of the list).
43 When interpreting the list, \fBlset\fR observes the same rules
44 concerning braces and quotes and backslashes as the Tcl command
45 interpreter; however, variable
46 substitution and command substitution do not occur.
47 The command constructs a new list in which the designated element is
48 replaced with \fInewValue\fP.  This new list is stored in the
49 variable \fIvarName\fP, and is also the return value from the \fBlset\fP
50 command.
51 .PP
52 If \fIindex\fR is negative or greater than or equal to the number
53 of elements in \fI$varName\fR, then an error occurs.
54 .PP
55 If \fIindex\fR has the value \fBend\fR, it refers to the last element
56 in the list, and \fBend\-\fIinteger\fR refers to the last element in
57 the list minus the specified integer offset.
58 .PP
59 If additional \fIindex\fR arguments are supplied, then each argument is
60 used in turn to address an element within a sublist designated
61 by the previous indexing operation,
62 allowing the script to alter elements in sublists.  The command,
63 .CS
64 lset a 1 2 newValue
65 .CE
66 or
67 .CS
68 lset a {1 2} newValue
69 .CE
70 replaces element 2 of sublist 1 with \fInewValue\fP.
71 .PP
72 The integer appearing in each \fIindex\fR argument must be greater
73 than or equal to zero.  The integer appearing in each \fIindex\fR
74 argument must be strictly less than the length of the corresponding
75 list.  In other words, the \fBlset\fR command cannot change the size
76 of a list.  If an index is outside the permitted range, an error is reported.
77 .SH EXAMPLES
78 In each of these examples, the initial value of \fIx\fP is:
79 .CS
80 set x [list [list a b c] [list d e f] [list g h i]]
81   => {a b c} {d e f} {g h i}
82 .CE
83 The indicated return value also becomes the new value of \fIx\fP.
84 .CS
85 lset x {j k l} => j k l
86 lset x {} {j k l} => j k l
87 lset x 0 j => j {d e f} {g h i}
88 lset x 2 j => {a b c} {d e f} j
89 lset x end j => {a b c} {d e f} j
90 lset x end-1 j => {a b c} j {d e f}
91 lset x 2 1 j => {a b c} {d e f} {g j i}
92 lset x {2 1} j => {a b c} {d e f} {g j i}
93 lset x {2 3} j
94 .CE
95 In the following examples, the initial value of \fIx\fP is:
96 .CS
97 set x [list [list [list a b] [list c d]] \e
98             [list [list e f] [list g h]]]
99  => {{a b} {c d}} {{e f} {g h}}
100 .CE
101 The indicated return value also becomes the new value of \fIx\fP.
102 .CS
103 lset x 1 1 0 j => {{a b} {c d}} {{e f} {j h}}
104 lset x {1 1 0} j => {{a b} {c d}} {{e f} {j h}}
105 .CE
106 .SH "SEE ALSO"
107 list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n), 
108 lsort(n), lrange(n), lreplace(n)
109
110 .SH KEYWORDS
111 element, index, list, replace, set