Message Boards Message Boards

0
|
4074 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Use of the OptionQ function

Today I''ve noticed interesting discrepancy between the Wolfram Language and its Documentation Center. I wrote a simple function which uses the built-in LinearSolve inside, and in order to allow myself in future pass all possible Options to the latter one I added an auxiliary argument in the form:

myFunc[myArgs__, opts___?OptionQ] := ...

(sure that "myArgs" are specified in more precise way in my code, but it does not matter here)

I read about the OptionQ function in the "Mathematica Programming: An Advanced Introduction" by Leonid Shifrin and used it in all cases like that with no doubt. But this time I tried to look in the documentation if this fucntion returns True for all inputs with head Rule or not. And surprisingly I have not found the corresponding page in the Documentation Center.

So, the question is: should I continue using OptionQ function for my purposes or it is obsolete and it will be removed in the upcoming versions of the Wolfram Language? It is first time I can't find documentation for a fucntion known to the system.

POSTED BY: Nikolay Shilov
3 Replies

Thanks for your replies!

POSTED BY: Nikolay Shilov

OptionQ seems effectively deprecated in favor of OptionsPattern, but I cannot imagine it being removed from a future release.

Just giving it various inputs, OptionQ seems to return true for any Rule or RuleDelayed that has a symbol or string as the left-hand side. It also returns True for any arbitrarily nested list of these.

In[14]:= OptionQ["foo" -> 4]

Out[14]= True

In[15]:= OptionQ[foo -> 4]

Out[15]= True

In[16]:= OptionQ[5 -> "foo"]

Out[16]= False

In[17]:= OptionQ[{foo} -> "foo"]

Out[17]= False

In[18]:= OptionQ[{{{foo -> 4}}, "bar" :> 3}]

Out[18]= True
POSTED BY: Jason Biggs
Posted 3 years ago

Checkout OptionsPattern[].

I've only been using the Wolfram Language for a little more than a year now. But OptionsPattern[] seems to do what you are looking for.

Please note that I cannot find OptionQ in the documentation.

But, in the pop-up definition, it says this function returns true if the expression can be considered to be an option or a list of options.

POSTED BY: Mike Besso
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract