summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2008-03-16 12:38:17 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2008-03-16 12:38:17 (GMT)
commitd01508be08a3ab6decdbb64d4a1fd313107d6992 (patch)
tree2f549517b5a0b5f0b2b93e499e59ca59da235a54 /doc
parentbd688c3b4dd5db4f0a7b0d911efa133f87527569 (diff)
downloadtcl-d01508be08a3ab6decdbb64d4a1fd313107d6992.zip
tcl-d01508be08a3ab6decdbb64d4a1fd313107d6992.tar.gz
tcl-d01508be08a3ab6decdbb64d4a1fd313107d6992.tar.bz2
Clarified documentation of what happens with negative indices. [Bug 1905809]
Added example, tidied up formatting.
Diffstat (limited to 'doc')
-rw-r--r--doc/lreplace.n39
1 files changed, 22 insertions, 17 deletions
diff --git a/doc/lreplace.n b/doc/lreplace.n
index 23e49f2..8510a84 100644
--- a/doc/lreplace.n
+++ b/doc/lreplace.n
@@ -5,9 +5,9 @@
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
-'\"
-'\" RCS: @(#) $Id: lreplace.n,v 1.16 2007/12/13 15:22:32 dgp Exp $
-'\"
+'\"
+'\" RCS: @(#) $Id: lreplace.n,v 1.17 2008/03/16 12:38:18 dkf Exp $
+'\"
.so man.macros
.TH lreplace n 7.4 Tcl "Tcl Built-In Commands"
.BS
@@ -17,14 +17,13 @@ lreplace \- Replace elements in a list with new elements
.SH SYNOPSIS
\fBlreplace \fIlist first last \fR?\fIelement element ...\fR?
.BE
-
.SH DESCRIPTION
.PP
\fBlreplace\fR returns a new list formed by replacing one or more elements of
\fIlist\fR with the \fIelement\fR arguments.
.VS 8.5
\fIfirst\fR and \fIlast\fR are index values specifying the first and
-last elements of the range to replace.
+last elements of the range to replace.
The index values \fIfirst\fR and \fIlast\fR are interpreted
the same as index values for the command \fBstring index\fR,
supporting simple index arithmetic and indices relative to the
@@ -33,16 +32,16 @@ end of the list.
list, and \fBend\fR refers to the last element of the list.
If \fIlist\fR is empty, then \fIfirst\fR and \fIlast\fR are ignored.
.VE
-
-If \fIfirst\fR is less than zero, it is considered to refer to the
+.PP
+If \fIfirst\fR is less than zero, it is considered to refer to before the
first element of the list. For non-empty lists, the element indicated
-by \fIfirst\fR must exist.
-
-If \fIlast\fR is less than zero but greater than \fIfirst\fR, then any
-specified elements will be prepended to the list. If \fIlast\fR is
-less than \fIfirst\fR then no elements are deleted; the new elements
-are simply inserted before \fIfirst\fR.
-
+by \fIfirst\fR must exist or \fIfirst\fR must indicate before the
+start of the list.
+.PP
+If \fIlast\fR is less than \fIfirst\fR, then any specified elements
+will be inserted into the list at the point specified by \fIfirst\fR
+with no elements being deleted.
+.PP
The \fIelement\fR arguments specify zero or more new arguments to
be added to the list in place of those that were deleted.
Each \fIelement\fR argument will become a separate element of
@@ -69,14 +68,20 @@ a b c d e
% set var [\fBlreplace\fR $var end end]
a b c d
.CE
-
+.PP
+A procedure to delete a given element from a list:
+.CS
+proc lremove {listVariable value} {
+ upvar 1 $listVariable var
+ set idx [lsearch -exact $var $value]
+ set var [\fBlreplace\fR $var $idx $idx]
+}
+.CE
.SH "SEE ALSO"
list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n),
lset(n), lrange(n), lsort(n),
.VS 8.5
string(n)
.VE
-
-
.SH KEYWORDS
element, list, replace