FunctionsWithOption
Posted on: Monday, March 23, 2009 at 03:59 PM UT
Here is the documentation for the FunctionsWithOption notebook. Click on the following link to down load it (for some browsers you will have to right click and choose "save as..."; also if your system appends a .txt or other string to the end of the file name, you will have to change it to .nb).
Download the FunctionsWithOption Notebook >>
The full text of the documentation that follows is contained in the FunctionsWithOption Notebook itself.
Purpose
FunctionsWithOption is a simple tool that allows you to find functions that have a particular option. In a way it is an inverse of Mathematica's Options function. Whereas the function Options will give you a list of all of the options for a particular function, e.g.:
FunctionsWithOption will give you all the functions that have a particular option
The form of this output is a list of pairs. The first item in each pair is the function
Various forms of use: Single argument form
Single argument form
FunctionsWithOption takes on several different argument sets. The first is the simplest. This is a single argument with the option that you are interested in as in the preceding example. Here is another example:
Note that, in this form, FunctionsWithOption looks for all of those functions that have the queried option in the Context of that option. It will not return any results for other Contexts that have functions that use that option. So, in the above example FunctionsWithOption is looking for all of the functions that have the TaggingRules option in the System` Context because
Care with the Global` Context
Note also that if the single argument form FunctionsWithOption is called with a symbol from a Context that hasn't yet been loaded, then that symbol will be placed in the Global` Context. This may not be quite what you want. There is an option to FunctionsWithOption, DeleteGlobalVersion, which if set as DeleteGlobalVersion→True (the default setting), causes any symbol that is introduced into the Global` Context through the execution of FunctionsWithOption, to be removed.
Here is an example.
First make sure that there is no current symbol called testSymbol
Now execute FunctionsWithOption with DeleteGlobalVersion→True:
The symbol still is not in the Global` context:
It we had executed this with DeleteGlobalVersion→True then testSymbol would remain in the Global` Context after execution:
To clean things up for this example Remove testSymbol:
Two argument forms
There are several two argument forms for FunctionsWithOption. In all cases the first argument is the symbol that you are querying.
Symbol and Context
For this case the second argument is the Context that you are looking in. If that Context has not yet been loaded then FunctionsWithOption will load it before looking for the functions in that context that have the queried option. Only those functions in the Context that have the symbol as an option will be returned: all other contexts will be ignored. Here is an example for the Combinatorica package. Combinatorica is not loaded by default when Mathematica is first started, but this command will load it. In this example we are using the option Grid→True to show a formatted output:
Even though the symbol Method is defined in the System` context, it is used in some Combinatorica functions:
Symbol and a list of Contexts
The second argument of FunctionsWithOption can also be a list of Contexts. In this case FunctionsWithOption returns all of the functions from each of the contexts that have the option.
Here are the functions in the System` Context that have the option Initialization:
Here are the functions in the Combinatorica` Context that have the option Initialization:
And here are the functions in both the System` and Combinatorica` context that have the Initialization option:
A warning:
You might be tempted to execute something like (the following cell is not an executable cell so that you do not accidentally execute it):
FunctionsWithOption[Initialization, Contexts[]]
Note however that this may cause Mathematica to attempt to initialize many of its data paclets which, in addition to possibly taking a very long time, may also cause a large amount of data to be written to your disk.
Symbol and a symbol
The final form is where the second argument for FunctionsWithOption is a symbol. In this case all of the functions from the context of the second argument are returned that have the first argument as an Option.
AnimateGraph is a function in the Combinatorica package:
AnimateGraph |
Initialization:→None |
Plot is a function in the System` Context:
Note that if the Context of the symbol in second argument has not been loaded when FunctionsWithOption is executed then that symbol will be placed in the Global` Context. In this case you are not likely to get the results you were expecting.
Symbol and a list of symbols
As in case of explicitly supplying a list of contexts, the second argument for FunctionsWithOption can take a list of symbols. In this case all of the functions from the set of Contexts for theses symbols that have the option are returned. Here Plot is in the System` context and NecklacePolynomial is in the Combinatorica` context:
Options
FunctionsWithOption takes several options:
The option Grid determines whether the result form FunctionsWithOption is returned in a formatted grid. We showed several examples of this above.
Here are the usage messages for the options LoadContext, ExcluedGlobalContext, and DeleteGlobal:
The remaining explicit options to FunctionsWithOption—Frame and Alignment—are used when Grid→True to format the gridded output. But FunctionsWithOption can also take on any other of the options to Grid as in the following:
Permalink | Comments | Add Comment...
|