Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Taking either a sequence or a list

  • To: mathgroup at
  • Subject: [mg63398] Re: [mg63318] Re: Taking either a sequence or a list
  • From: "Oyvind Tafjord" <tafjord at>
  • Date: Thu, 29 Dec 2005 02:57:29 -0500 (EST)
  • References: <dnm29m$89q$> <dnopf9$2gp$> <dnrd16$kqf$> <>
  • Sender: owner-wri-mathgroup at

----- Original Message ----- 
From: "Maxim" <m.r at>
To: mathgroup at
Subject: [mg63398] [mg63318] Re: Taking either a sequence or a list

>> This definitely looks like an inconsistency:
>> In[1]:= MatchQ[{a}, {__Integer | a}]
>> Out[1]= True
>> In[2]:= MatchQ[{a}, {x : __Integer | a}]
>> Out[2]= False

This is a known issue (inconsistent handling of Alternatives) which is fixed 
in future versions.

>> It is also unclear exactly what value is assigned to x here:
>> In[4]:= tmp = {a} /. {x : __} -> x
>> Out[4]= a
>> In[5]:= tmp2 = {a} /. {x : __ | __} -> x
>> Out[5]= Sequence[a]

The result should be "a" in both cases (don't wrap Sequence around 
single-element sequences), fixed in future versions (by the same fix as the 

> Here's another curious inconsistency:
> In[1]:= MatchQ[{a, a}, {s_, s_} /; True /; False]
> Out[1]= False
> In[2]:= MatchQ[{a, a}, {s__, s__} /; True /; False]
> Out[2]= True

This is a bug I haven't seen before, involving nested 
Conditions/PatternTests surrounding "non-unique" patterns. Will be fixed in 
future versions. Thanks for pointing it out.

Oyvind Tafjord
Wolfram Research

> Perhaps Mathematica takes some shortcuts when dealing with patterns that
> require a combinatorial search (sequences or Orderless/Flat functions),
> but such 'simplified' handling of certain classes of patterns can produce
> rather strange results.
> Maxim Rytin
> m.r at 

  • Prev by Date: Re: Making a new definition of Equal work with lists as well
  • Next by Date: Can I assign a style to a GridBox row?
  • Previous by thread: Re: Taking either a sequence or a list
  • Next by thread: Re: Re: Taking either a sequence or a list