Re: Taking either a sequence or a list

• To: mathgroup at smc.vnet.net
• Subject: [mg63135] Re: Taking either a sequence or a list
• From: Maxim <m.r at inbox.ru>
• Date: Thu, 15 Dec 2005 03:06:44 -0500 (EST)
• References: <dnm29m\$89q\$1@smc.vnet.net> <dnopf9\$2gp\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On Wed, 14 Dec 2005 09:43:05 +0000 (UTC), dh <dh at metrohm.ch> wrote:

>
> I first tried the more obvious:
>
> f[ x : (__Integer | {__Integer})]
>
> but this doesn not work. It is not clear to my why not, but may be there
> is somebody who has an explanation.
>

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

Just adding a pattern name shouldn't change the outcome. The problem is
that one alternative is a sequence and another is a single element. This
would work:

In[3]:= MatchQ[{a}, {x : __Integer | (a)..}]

Out[3]= True

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]

In[6]:= (HoldComplete[tmp] /. OwnValues[tmp]) ===
(HoldComplete[tmp2] /. OwnValues[tmp2])

Out[6]= False

So there might be some discrepancy if the results are later used as
arguments to functions with the attribute SequenceHold.

Maxim Rytin
m.r at inbox.ru

```

• Prev by Date: Re: Parametric Numerical Integral
• Next by Date: Re: Remote Mathematica kernels and SSH password
• Previous by thread: Re: Taking either a sequence or a list
• Next by thread: Re: Taking either a sequence or a list