OSDN Git Service

Updated to tcl 8.4.1
[pf3gnuchains/sourceware.git] / tcl / doc / lsearch.n
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.  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$
10 '\" 
11 .so man.macros
12 .TH lsearch n 8.4 Tcl "Tcl Built-In Commands"
13 .BS
14 '\" Note:  do not modify the .SH NAME line immediately below!
15 .SH NAME
16 lsearch \- See if a list contains a particular element
17 .SH SYNOPSIS
18 \fBlsearch \fR?\fIoptions\fR? \fIlist pattern\fR
19 .BE
20
21 .SH DESCRIPTION
22 .PP
23 This command searches the elements of \fIlist\fR to see if one
24 of them matches \fIpattern\fR.  If so, the command returns the index
25 of the first matching element
26 .VS 8.4
27 (unless the options \fB\-all\fR or \fB\-inline\fR are specified.)
28 .VE 8.4
29 If not, the command returns \fB\-1\fR.  The \fIoption\fR arguments
30 indicates how the elements of the list are to be matched against
31 \fIpattern\fR and it must have one of the following values:
32 .TP
33 \fB\-all\fR
34 .VS 8.4
35 Changes the result to be the list of all matching indices (or all
36 matching values if \fB\-inline\fR is specified as well.)
37 .VE 8.4
38 .TP
39 \fB\-ascii\fR
40 The list elements are to be examined as ASCII strings.  This option is only
41 meaningful when used with \fB\-exact\fR or \fB\-sorted\fR.
42 .TP
43 \fB\-decreasing\fR
44 The list elements are sorted in decreasing order.  This option is only
45 meaningful when used with \fB\-sorted\fR.
46 .TP
47 \fB\-dictionary\fR
48 The list elements are to be compared using dictionary-style
49 comparisons.  This option is only meaningful when used with
50 \fB\-exact\fR or \fB\-sorted\fR.
51 .TP
52 \fB\-exact\fR
53 The list element must contain exactly the same string as \fIpattern\fR.
54 .TP
55 \fB\-glob\fR
56 \fIPattern\fR is a glob-style pattern which is matched against each list
57 element using the same rules as the \fBstring match\fR command.
58 .TP
59 \fB\-increasing\fR
60 The list elements are sorted in increasing order.  This option is only
61 meaningful when used with \fB\-sorted\fR.
62 .TP
63 \fB\-inline\fR
64 .VS 8.4
65 The matching value is returned instead of its index (or an empty
66 string if no value matches.)  If \fB\-all\fR is also specified, then
67 the result of the command is the list of all values that matched.
68 .VE 8.4
69 .TP
70 \fB\-integer\fR
71 The list elements are to be compared as integers.  This option is only
72 meaningful when used with \fB\-exact\fR or \fB\-sorted\fR.
73 .TP
74 \fB\-not\fR
75 .VS 8.4
76 This negates the sense of the match, returning the index of the first
77 non-matching value in the list.
78 .VE 8.4
79 .TP
80 \fB\-real\fR
81 The list elements are to be compared as floating-point values.  This
82 option is only meaningful when used with \fB\-exact\fR or \fB\-sorted\fR.
83 .TP
84 \fB\-regexp\fR
85 \fIPattern\fR is treated as a regular expression and matched against
86 each list element using the rules described in the \fBre_syntax\fR
87 reference page.
88 .TP
89 \fB\-sorted\fR
90 The list elements are in sorted order.  If this option is specified,
91 \fBlsearch\fR will use a more efficient searching algorithm to search
92 \fIlist\fR.  If no other options are specified, \fIlist\fR is assumed
93 to be sorted in increasing order, and to contain ASCII strings.  This
94 option is mutually exclusive with \fB\-glob\fR and \fB\-regexp\fR, and
95 is treated exactly like \fB-exact\fR when either \fB\-all\fR, or
96 \fB\-not\fR is specified.
97 .TP
98 \fB\-start\fR \fIindex\fR
99 .VS 8.4
100 The list is searched starting at position \fIindex\fR.  If \fIindex\fR
101 has the value \fBend\fR, it refers to the last element in the list,
102 and \fBend\-\fIinteger\fR refers to the last element in the list minus
103 the specified integer offset.
104 .VE 8.4
105 .PP
106 If \fIoption\fR is omitted then it defaults to \fB\-glob\fR.  If more
107 than one of \fB\-exact\fR, \fB\-glob\fR, \fB\-regexp\fR, and
108 \fB\-sorted\fR is specified, whichever option is specified last takes
109 precedence.  If more than one of \fB\-ascii\fR, \fB\-dictionary\fR,
110 \fB\-integer\fR and \fB\-real\fR is specified, the option specified
111 last takes precedence.  If more than one of \fB\-increasing\fR and
112 \fB\-decreasing\fR is specified, the option specified last takes
113 precedence.
114
115 .VS 8.4
116 .SH EXAMPLES
117 .CS
118 lsearch {a b c d e} c => 2
119 lsearch -all {a b c a b c} c => 2 5
120 lsearch -inline {a20 b35 c47} b* => b35
121 lsearch -inline -not {a20 b35 c47} b* => a20
122 lsearch -all -inline -not {a20 b35 c47} b* => a20 c47
123 lsearch -all -not {a20 b35 c47} b* => 0 2
124 lsearch -start 3 {a b c a b c} c => 5
125 .CE
126 .VE 8.4
127
128 .SH "SEE ALSO"
129 .VS 8.4
130 foreach(n), list(n), lappend(n), lindex(n), linsert(n), llength(n), 
131 lset(n), lsort(n), lrange(n), lreplace(n)
132 .VE
133
134 .SH KEYWORDS
135 list, match, pattern, regular expression, search, string