4
$\begingroup$

What is the correct form of the pattern "list of variables of two (or more) types"

These examples do not work

 MatchQ[{1., "a", 2.3, 7.}, _ {Real | String...}]

False

MatchQ[{1., "a", 2.3, 7.}, _ {_Real | _String...}]

False

MatchQ[{1., "a", 2.3, 7.}, {_Real | _String ...}]

False

$\endgroup$
5
$\begingroup$

You were close on the last pattern,

In[4]:= MatchQ[{1., "a", 2.3, 7.}, {(_Real | _String) ...}]

Out[4]= True

Compare the FullForm of the two patterns to see the difference,

In[6]:= FullForm[{_Real|_String...}]

Out[6]//FullForm= List[Alternatives[Blank[Real],RepeatedNull[Blank[String]]]]

In[7]:= FullForm[{(_Real|_String)...}]

Out[7]//FullForm= List[RepeatedNull[Alternatives[Blank[Real],Blank[String]]]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.