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

NAME

8       lreplace - Replace elements in a list with new elements
9

SYNOPSIS

11       lreplace list first last ?element element ...?
12_________________________________________________________________
13
14

DESCRIPTION

16       lreplace returns a new list formed by replacing one or more elements of
17       list with the element arguments.  first and last specify the first  and
18       last  index of the range of elements to replace.  0 refers to the first
19       element of the list, and end (or any abbreviation of it) may be used to
20       refer  to  the  last element of the list.  If list is empty, then first
21       and last are ignored.
22
23       If first is less than zero, it is considered to refer to the first ele‐
24       ment  of the list.  For non-empty lists, the element indicated by first
25       must exist.
26
27       If last is less than zero but greater than first,  then  any  specified
28       elements  will  be  prepended  to the list.  If last is less than first
29       then no elements are deleted; the  new  elements  are  simply  inserted
30       before first.
31
32       The element arguments specify zero or more new arguments to be added to
33       the list in place of those that were deleted.   Each  element  argument
34       will  become  a  separate element of the list.  If no element arguments
35       are specified, then the elements between  first  and  last  are  simply
36       deleted.   If list is empty, any element arguments are added to the end
37       of the list.
38

EXAMPLES

40       Replacing an element of a list with another:
41              % lreplace {a b c d e} 1 1 foo
42              a foo c d e
43
44       Replacing two elements of a list with three:
45              % lreplace {a b c d e} 1 2 three more elements
46              a three more elements d e
47
48       Deleting the last element from a list in a variable:
49              % set var {a b c d e}
50              a b c d e
51              % set var [lreplace $var end end]
52              a b c d
53
54

SEE ALSO

56       list(n), lappend(n),  lindex(n),  linsert(n),  llength(n),  lsearch(n), │
57       lset(n), lrange(n), lsort(n)
58
59

KEYWORDS

61       element, list, replace
62
63
64
65Tcl                                   7.4                          lreplace(n)
Impressum