       Re: Taking either a sequence or a list

• To: mathgroup at smc.vnet.net
• Subject: [mg63318] Re: Taking either a sequence or a list
• From: Maxim <m.r at inbox.ru>
• Date: Fri, 23 Dec 2005 05:08:40 -0500 (EST)
• References: <dnm29m\$89q\$1@smc.vnet.net> <dnopf9\$2gp\$1@smc.vnet.net> <dnrd16\$kqf\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

On Thu, 15 Dec 2005 09:29:10 +0000 (UTC), Maxim <m.r at inbox.ru> wrote:

> 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:= MatchQ[{a}, {__Integer | a}]
>
> Out= True
>
> In:= MatchQ[{a}, {x : __Integer | a}]
>
> Out= 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:= MatchQ[{a}, {x : __Integer | (a)..}]
>
> Out= True
>
> It is also unclear exactly what value is assigned to x here:
>
> In:= tmp = {a} /. {x : __} -> x
>
> Out= a
>
> In:= tmp2 = {a} /. {x : __ | __} -> x
>
> Out= Sequence[a]
>
> In:= (HoldComplete[tmp] /. OwnValues[tmp]) ===
>    (HoldComplete[tmp2] /. OwnValues[tmp2])
>
> Out= 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
>

Here's another curious inconsistency:

In:= MatchQ[{a, a}, {s_, s_} /; True /; False]

Out= False

In:= MatchQ[{a, a}, {s__, s__} /; True /; False]

Out= True

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 inbox.ru

• Prev by Date: Re: Converting Strings to Ints.
• Next by Date: Re: Returning an empty sequence
• Previous by thread: Re: Taking either a sequence or a list
• Next by thread: Re: Re: Taking either a sequence or a list