Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / share / tcl / help / tcl / lists / lsearch
1 NAME
2 lsearch - See if a list contains a particular element
3
4 SYNOPSIS
5 lsearch ?options? list pattern
6
7
8 DESCRIPTION
9 This command searches the elements of list to see if one of them
10 matches pattern. If so, the command returns the index of the first
11 matching element (unless the options -all or -inline are specified.)
12 If not, the command returns -1. The option arguments indicates how the
13 elements of the list are to be matched against pattern and it must have
14 one of the following values:
15
16 -all Changes the result to be the list of all matching indices (or
17 all matching values if -inline is specified as well.)
18
19 -ascii The list elements are to be examined as Unicode strings (the
20 name is for backward-compatability reasons.) This option is
21 only meaningful when used with -exact or -sorted.
22
23 -decreasing
24 The list elements are sorted in decreasing order. This option
25 is only meaningful when used with -sorted.
26
27 -dictionary
28 The list elements are to be compared using dictionary-style com-
29 parisons (see lsort for a fuller description). This option is
30 only meaningful when used with -exact or -sorted, and it is only
31 distinguishable from the -ascii option when the -sorted option
32 is given, because values are only dictionary-equal when exactly
33 equal.
34
35 -exact The list element must contain exactly the same string as pat-
36 tern.
37
38 -glob Pattern is a glob-style pattern which is matched against each
39 list element using the same rules as the string match command.
40
41 -increasing
42 The list elements are sorted in increasing order. This option
43 is only meaningful when used with -sorted.
44
45 -inline
46 The matching value is returned instead of its index (or an empty
47 string if no value matches.) If -all is also specified, then
48 the result of the command is the list of all values that
49 matched.
50
51 -integer
52 The list elements are to be compared as integers. This option
53 is only meaningful when used with -exact or -sorted.
54
55 -not This negates the sense of the match, returning the index of the
56 first non-matching value in the list.
57
58 -real The list elements are to be compared as floating-point values.
59 This option is only meaningful when used with -exact or -sorted.
60
61 -regexp
62 Pattern is treated as a regular expression and matched against
63 each list element using the rules described in the re_syntax
64 reference page.
65
66 -sorted
67 The list elements are in sorted order. If this option is speci-
68 fied, lsearch will use a more efficient searching algorithm to
69 search list. If no other options are specified, list is assumed
70 to be sorted in increasing order, and to contain ASCII strings.
71 This option is mutually exclusive with -glob and -regexp, and is
72 treated exactly like -exact when either -all, or -not is speci-
73 fied.
74
75 -start index
76 The list is searched starting at position index. If index has
77 the value end, it refers to the last element in the list, and
78 end-integer refers to the last element in the list minus the
79 specified integer offset.
80
81 If option is omitted then it defaults to -glob. If more than one of
82 -exact, -glob, -regexp, and -sorted is specified, whichever option is
83 specified last takes precedence. If more than one of -ascii, -dictio-
84 nary, -integer and -real is specified, the option specified last takes
85 precedence. If more than one of -increasing and -decreasing is speci-
86 fied, the option specified last takes precedence.
87
88
89 EXAMPLES
90 lsearch {a b c d e} c => 2
91 lsearch -all {a b c a b c} c => 2 5
92 lsearch -inline {a20 b35 c47} b* => b35
93 lsearch -inline -not {a20 b35 c47} b* => a20
94 lsearch -all -inline -not {a20 b35 c47} b* => a20 c47
95 lsearch -all -not {a20 b35 c47} b* => 0 2
96 lsearch -start 3 {a b c a b c} c => 5
97
98
99 SEE ALSO
100 foreach(n), list(n), lappend(n), lindex(n), linsert(n), llength(n),
101 lset(n), lsort(n), lrange(n), lreplace(n)
102
103
104 KEYWORDS