prefix

Command introduced in Tcl 8.6 for easier management of the prefix-matching of strings.
https://www.tcl-lang.org/man/tcl8.6/TclCmd/prefix.htm

tcl::prefix subcommand

Currently supports three subcommands.

tcl::prefix all table string

This returns all values from the list, table, that start with string. (This answers the question “what values in the table start with a prefix?”)

tcl::prefix longest table string

Returns the longest prefix of the subset of values in the list, table, such that the values all begin with string. (This answers the question “what can I extend my current prefix to, while not changing the set of words which I've got a prefix of?” which is useful for tab-completion.)

tcl::prefix match options… table string

Returns the unique entry from the list, table, that string is a prefix of, or generates an error message.


KPV Here are the examples from the man page:

 namespace import ::tcl::prefix
 prefix match {apa bepa cepa} apa
         → apa
 prefix match {apa bepa cepa} a
         → apa
 prefix match -exact {apa bepa cepa} a
         → bad option "a": must be apa, bepa, or cepa
 prefix match -message "switch" {apa ada bepa cepa} a
         → ambiguous switch "a": must be apa, ada, bepa, or cepa
 prefix longest {fblocked fconfigure fcopy file fileevent flush} fc
         → fco
 prefix all {fblocked fconfigure fcopy file fileevent flush} fc
         → fconfigure fcopy

See Also