Debian Codegraph @

doc/lrange.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 lrange n 7.4 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 lrange \- Return one or more adjacent elements from a list
15 .SH SYNOPSIS
16 \fBlrange \fIlist first last\fR
17 .BE
18 .SH DESCRIPTION
19 .PP
20 \fIList\fR must be a valid Tcl list. This command will
21 return a new list consisting of elements
22 \fIfirst\fR through \fIlast\fR, inclusive.
23 The index values \fIfirst\fR and \fIlast\fR are interpreted
24 the same as index values for the command \fBstring index\fR,
25 supporting simple index arithmetic and indices relative to the
26 end of the list.
27 If \fIfirst\fR is less than zero, it is treated as if it were zero.
28 If \fIlast\fR is greater than or equal to the number of elements
29 in the list, then it is treated as if it were \fBend\fR.
30 If \fIfirst\fR is greater than \fIlast\fR then an empty string
31 is returned.
32 Note:
33 .QW "\fBlrange \fIlist first first\fR"
34 does not always produce the same result as
35 .QW "\fBlindex \fIlist first\fR"
36 (although it often does for simple fields that are not enclosed in
37 braces); it does, however, produce exactly the same results as
38 .QW "\fBlist [lindex \fIlist first\fB]\fR"
39 .SH EXAMPLES
40 .PP
41 Selecting the first two elements:
42 .PP
43 .CS
44 % \fBlrange\fR {a b c d e} 0 1
45 a b
46 .CE
47 .PP
48 Selecting the last three elements:
49 .PP
50 .CS
51 % \fBlrange\fR {a b c d e} end-2 end
52 c d e
53 .CE
54 .PP
55 Selecting everything except the first and last element:
56 .PP
57 .CS
58 % \fBlrange\fR {a b c d e} 1 end-1
59 b c d
60 .CE
61 .PP
62 Selecting a single element with \fBlrange\fR is not the same as doing
63 so with \fBlindex\fR:
64 .PP
65 .CS
66 % set var {some {elements to} select}
67 some {elements to} select
68 % lindex $var 1
69 elements to
70 % \fBlrange\fR $var 1 1
71 {elements to}
72 .CE
73 .SH "SEE ALSO"
74 list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n),
75 lset(n), lreplace(n), lsort(n),
76 string(n)
77 .SH KEYWORDS
78 element, list, range, sublist