beetlebug▾
/

tsv lsearch

Finds an element of a list in a shared array.

tsv::lsearch ARRAY ELEMENT ?MODE? PATTERN

Description

The command tsv::lsearch searches the list in the element for PATTERN with lsearch, and gives the index of the first match or -1. MODE is one option of lsearch, such as -exact, -glob (the default), -regexp, -nocase, -all, or -inline.

Arguments

ArgumentTypeDefaultDescription
ARRAYarray namerequiredThe name of the shared array.
ELEMENTstringrequiredThe name of the element.
MODEan option of lsearch-globHow to match.
PATTERNglob pattern, value, or regular expressionrequiredWhat to find.

Returns

The result of lsearch: an index or -1, or a list with -all or -inline.

Examples

% tsv::set l x {apple box ant}
> tsv::lsearch l x b*
1

% tsv::set l x {apple box ant}
> tsv::lsearch l x -exact a*
-1

% tsv::set l x {a b a}
> tsv::lsearch l x -all a
0 2

Errors

% tsv::set l x {a b}
> tsv::lsearch l x
wrong # args: should be "tsv::lsearch l x ?mode? pattern"
-errorcode TCL WRONGARGS

# Tcl 9.1 only
% tsv::set l x {a b}
> tsv::lsearch l x -bogus a
bad option "-bogus": must be -all, -ascii, -bisect, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, -stride, or -subindices
-errorcode TCL LOOKUP INDEX option -bogus

# Tcl 8.6 only
% tsv::set l x {a b}
> tsv::lsearch l x -bogus a
bad option "-bogus": must be -all, -ascii, -bisect, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, or -subindices
-errorcode TCL LOOKUP INDEX option -bogus

Tcl 8.6 and Tcl 9.1

Facts

Capability
thread. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also