programming.nbk: Home | Index | Next Page: Tcl: list | Previous Page: tcl: lappend listVar arg arg...


 Tcl: lindex

Retrieves an element from a list.

lindex list ?index...?

If no indices are specified, the entire list is returned.

    lindex {a b c}  => a b c
    lindex {a b c} {} => a b c

If a single index is specified, that element of the element is returned. If the index is greater than or equal to the number of elements in the list, or is negative, an empty string is returned.

    lindex {a b c} 0 => a
    lindex {a b c} 2 => c
    lindex {a b c} 3 => <empty string>

If the index has the value end, the last element of the list is returned. If the index has the value end-integer, the corresponding element from the end is returned.

    lindex {a b c} end => c
    lindex {a b c} end-1 => b

If addtional indices are specified, each is applied to the list resulting from the application of the previous index.

    lindex {{{a b} {c d}} {{e f} {g h}}} {1 1 0} => g

programming.nbk: Home | Index | Next Page: Tcl: list | Previous Page: tcl: lappend listVar arg arg...


Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time