Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/lreplace.n @ 37

Last change on this file since 37 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 2.8 KB
Line 
1'\"
2'\" Copyright (c) 1993 The Regents of the University of California.
3'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4'\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>.  All rights reserved.
5'\"
6'\" See the file "license.terms" for information on usage and redistribution
7'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8'\"
9'\" RCS: @(#) $Id: lreplace.n,v 1.19 2008/03/26 09:59:22 dkf Exp $
10'\"
11.so man.macros
12.TH lreplace n 7.4 Tcl "Tcl Built-In Commands"
13.BS
14'\" Note:  do not modify the .SH NAME line immediately below!
15.SH NAME
16lreplace \- Replace elements in a list with new elements
17.SH SYNOPSIS
18\fBlreplace \fIlist first last \fR?\fIelement element ...\fR?
19.BE
20.SH DESCRIPTION
21.PP
22\fBlreplace\fR returns a new list formed by replacing one or more elements of
23\fIlist\fR with the \fIelement\fR arguments.
24.VS 8.5
25\fIfirst\fR and \fIlast\fR are index values specifying the first and
26last elements of the range to replace.
27The index values \fIfirst\fR and \fIlast\fR are interpreted
28the same as index values for the command \fBstring index\fR,
29supporting simple index arithmetic and indices relative to the
30end of the list.
310 refers to the first element of the
32list, and \fBend\fR refers to the last element of the list.
33If \fIlist\fR is empty, then \fIfirst\fR and \fIlast\fR are ignored.
34.VE
35.PP
36If \fIfirst\fR is less than zero, it is considered to refer to before the
37first element of the list.  For non-empty lists, the element indicated
38by \fIfirst\fR must exist or \fIfirst\fR must indicate before the
39start of the list.
40.PP
41If \fIlast\fR is less than \fIfirst\fR, then any specified elements
42will be inserted into the list at the point specified by \fIfirst\fR
43with no elements being deleted.
44.PP
45The \fIelement\fR arguments specify zero or more new arguments to
46be added to the list in place of those that were deleted.
47Each \fIelement\fR argument will become a separate element of
48the list.  If no \fIelement\fR arguments are specified, then the elements
49between \fIfirst\fR and \fIlast\fR are simply deleted.  If \fIlist\fR
50is empty, any \fIelement\fR arguments are added to the end of the list.
51.SH EXAMPLES
52Replacing an element of a list with another:
53.CS
54% \fBlreplace\fR {a b c d e} 1 1 foo
55a foo c d e
56.CE
57.PP
58Replacing two elements of a list with three:
59.CS
60% \fBlreplace\fR {a b c d e} 1 2 three more elements
61a three more elements d e
62.CE
63.PP
64Deleting the last element from a list in a variable:
65.CS
66% set var {a b c d e}
67a b c d e
68% set var [\fBlreplace\fR $var end end]
69a b c d
70.CE
71.PP
72A procedure to delete a given element from a list:
73.CS
74proc lremove {listVariable value} {
75    upvar 1 $listVariable var
76    set idx [lsearch -exact $var $value]
77    set var [\fBlreplace\fR $var $idx $idx]
78}
79.CE
80.SH "SEE ALSO"
81list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n),
82lset(n), lrange(n), lsort(n),
83.VS 8.5
84string(n)
85.VE
86.SH KEYWORDS
87element, list, replace
Note: See TracBrowser for help on using the repository browser.