prefix

Difference between version 3 and 4 - Previous - Next
[Command] introduced in [Tcl] 8.6 for easier management of the prefix-matching of [string]s. <<br>>
http://www.tcl.tk/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**

   * [Forward-compatible tcl::prefix]
   * [https://wiki.tcl-lang.org/page/dispatch#f295cc474c2cd9ae047b9eaf124c94d134bc153bfd4f32b9c14b9459953c9bdd%|%dispatch (Andy Goth)]

<<categories>> Command