1linsert(n) Tcl Built-In Commands linsert(n)
2
3
4
5______________________________________________________________________________
6
8 linsert - Insert elements into a list
9
11 linsert list index ?element element ...?
12______________________________________________________________________________
13
15 This command produces a new list from list by inserting all of the ele‐
16 ment arguments just before the index'th element of list. Each element
17 argument will become a separate element of the new list. If index is
18 less than or equal to zero, then the new elements are inserted at the
19 beginning of the list, and if index is greater or equal to the length
20 of list, it is as if it was end. As with string index, the index value
21 supports both simple index arithmetic and end-relative indexing.
22
23 Subject to the restrictions that indices must refer to locations inside
24 the list and that the elements will always be inserted in order, inser‐
25 tions are done so that when index is start-relative, the first element
26 will be at that index in the resulting list, and when index is end-rel‐
27 ative, the last element will be at that index in the resulting list.
28
30 Putting some values into a list, first indexing from the start and then
31 indexing from the end, and then chaining them together:
32
33 set oldList {the fox jumps over the dog}
34 set midList [linsert $oldList 1 quick]
35 set newList [linsert $midList end-1 lazy]
36 # The old lists still exist though...
37 set newerList [linsert [linsert $oldList end-1 quick] 1 lazy]
38
40 list(n), lappend(n), lindex(n), llength(n), lsearch(n), lset(n),
41 lsort(n), lrange(n), lreplace(n), string(n)
42
44 element, insert, list
45
46
47
48Tcl 8.2 linsert(n)