1lindex(n)                    Tcl Built-In Commands                   lindex(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       lindex - Retrieve an element from a list
9

SYNOPSIS

11       lindex list ?index...?
12_________________________________________________________________
13

DESCRIPTION

15       The  lindex command accepts a parameter, list, which it treats as a Tcl
16       list. It also accepts zero or more indices into the list.  The  indices
17       may  be  presented either consecutively on the command line, or grouped
18       in a Tcl list and presented as a single argument.
19
20       If no indices are presented, the command takes the form:
21              lindex list
22       or
23              lindex list {}
24       In this case, the return value of lindex is simply  the  value  of  the
25       list parameter.
26
27       When presented with a single index, the lindex command treats list as a
28       Tcl list and returns the index'th element from  it  (0  refers  to  the
29       first element of the list).  In extracting the element, lindex observes
30       the same rules concerning braces and quotes and backslashes as the  Tcl
31       command interpreter; however, variable substitution and command substi‐
32       tution do not occur.  If index is negative or greater than or equal  to
33       the number of elements in value, then an empty string is returned.  The │
34       interpretation of each simple index value is the same as for  the  com‐ │
35       mand string index, supporting simple index arithmetic and indices rela‐ │
36       tive to the end of the list.
37
38       If additional index arguments are supplied, then each argument is  used
39       in  turn  to  select  an  element from the previous indexing operation,
40       allowing the script to select elements from sublists.  The command,
41              lindex $a 1 2 3
42       or
43              lindex $a {1 2 3}
44       is synonymous with
45              lindex [lindex [lindex $a 1] 2] 3
46

EXAMPLES

48              lindex {a b c}
49                     a b c
50              lindex {a b c} {}
51                     a b c
52              lindex {a b c} 0
53                     a
54              lindex {a b c} 2
55                     c
56              lindex {a b c} end
57                     c
58              lindex {a b c} end-1
59                     b
60              lindex {{a b c} {d e f} {g h i}} 2 1
61                     h
62              lindex {{a b c} {d e f} {g h i}} {2 1}
63                     h
64              lindex {{{a b} {c d}} {{e f} {g h}}} 1 1 0
65                     g
66              lindex {{{a b} {c d}} {{e f} {g h}}} {1 1 0}
67                     g
68

SEE ALSO

70       list(n),  lappend(n),  linsert(n),  llength(n),  lsearch(n),   lset(n),
71       lsort(n), lrange(n), lreplace(n), string(n)                             │
72
73

KEYWORDS

75       element, index, list
76
77
78
79Tcl                                   8.4                            lindex(n)
Impressum