This is not necessarily the current version of this TIP.
|Title:||Multiple 'dict filter' Patterns|
|Version:||$Revision: 1.1 $|
|Author:||Lars Hellstršm <Lars dot Hellstrom at residenset dot net>|
|Created:||Thursday, 27 November 2008|
|Keywords:||Tcl, set intersection|
The key and value forms of dict filter are generalised to allow an arbitrary number of patterns.
The two dict filter command forms
dict filter dictionary key pattern
dict filter dictionary value pattern
are generalised to
dict filter dictionary key ?pattern ...?
dict filter dictionary value ?pattern ...?
and the results are the sub-dictionaries of those keys and values respectively which match at least one of the patterns.
Although there are dict subcommands which allow deleting some keys from a dictionary (dict remove) and inserting some keys into a dictionary (dict replace), there is no direct way of requesting the sub-dictionary which only has keys from a given list; if we think of only the set of keys in the dictionary, then we have subcommands for set minus and set union, but none for set intersection. A situation where this would be useful is that the option dictionary for a high-level procedure can contain options meant to be passed on to lower level commands, and it is necessary to extract the subdictionary of options that the lower level command would accept (since passing one which is not supported would cause it to throw an error).
There is of course already the dict filter command, which indeed returns a subdictionary of an existing dictionary, but its key form only accepts one string match pattern and therefore cannot be used to e.g. select all three of -foo, -bar, and -baz (it could select both -bar and -baz through the pattern -ba[rz], but that's neither common nor particularly readable). However, in many instances where this kind of pattern