Debian Codegraph @

doc/linsert.n

raw
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 <[email protected]>. 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 .TH linsert n 8.2 Tcl "Tcl Built-In Commands"
10 .so man.macros
11 .BS
12 '\" Note: do not modify the .SH NAME line immediately below!
13 .SH NAME
14 linsert \- Insert elements into a list
15 .SH SYNOPSIS
16 \fBlinsert \fIlist index \fR?\fIelement element ...\fR?
17 .BE
18 .SH DESCRIPTION
19 .PP
20 This command produces a new list from \fIlist\fR by inserting all of the
21 \fIelement\fR arguments just before the \fIindex\fR'th element of
22 \fIlist\fR. Each \fIelement\fR argument will become a separate element of
23 the new list. If \fIindex\fR is less than or equal to zero, then the new
24 elements are inserted at the beginning of the list, and if \fIindex\fR is
25 greater or equal to the length of \fIlist\fR, it is as if it was \fBend\fR.
26 As with \fBstring index\fR, the \fIindex\fR value supports both simple index
27 arithmetic and end-relative indexing.
28 .PP
29 Subject to the restrictions that indices must refer to locations inside the
30 list and that the \fIelement\fRs will always be inserted in order, insertions
31 are done so that when \fIindex\fR is start-relative, the first \fIelement\fR
32 will be at that index in the resulting list, and when \fIindex\fR is
33 end-relative, the last \fIelement\fR will be at that index in the resulting
34 list.
35 .SH EXAMPLE
36 .PP
37 Putting some values into a list, first indexing from the start and
38 then indexing from the end, and then chaining them together:
39 .PP
40 .CS
41 set oldList {the fox jumps over the dog}
42 set midList [\fBlinsert\fR $oldList 1 quick]
43 set newList [\fBlinsert\fR $midList end-1 lazy]
44 # The old lists still exist though...
45 set newerList [\fBlinsert\fR [\fBlinsert\fR $oldList end-1 quick] 1 lazy]
46 .CE
47 .SH "SEE ALSO"
48 list(n), lappend(n), lindex(n), llength(n), lsearch(n),
49 lset(n), lsort(n), lrange(n), lreplace(n),
50 string(n)
51 .SH KEYWORDS
52 element, insert, list
53 '\" Local Variables:
54 '\" mode: nroff
55 '\" End: