Group Abstract Group Abstract

Message Boards Message Boards

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

Use of the OptionQ function

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 5 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