       Baffled By Underscore Pattern Matching

• To: mathgroup at smc.vnet.net
• Subject: [mg45992] Baffled By Underscore Pattern Matching
• From: Harold.Noffke at wpafb.af.mil (Harold Noffke)
• Date: Mon, 2 Feb 2004 05:20:27 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```MathGroup:

In my study of Mathematica 5.0, I have reached "The Mathematica Book >
Principals of Mathematica > Patterns > 2.3.8 Functions with Variable
Numbers of Arguments".  The In/Out example I understand, but the
In[2,3]/Out example (discussed below) has me totally mystified.

As printed, we have ...

In:= h[a___, x_, b___, x_, c___] := hh[x] h[a, b, c]

In:= h[2, 3, 2, 4, 5, 3]

Out= h[4, 5] hh hh

Now let's make a change to In ...

In:= Clear[h, hh]

In:= h[a___, x_, b___, x_, c___] := hh[x] h[{a}, {b}, {c}]

In:= h[2, 3, 2, 4, 5, 3]

Out= h[{}, {3}, {4, 5, 3}] hh

I did a Trace on this pattern match problem, and found only that
doublets were pulled out on each iteration.  In order to understand
what is happening here, I think I need to understand the matching
process at a level of granularity finer than Trace can supply.  I
don"t have a clear mental picture of how In manipulates the number
stream which feeds into it from In.  I have no idea of how the
In lists came to contain the numbers they do.

Any help, pointers to tutorial papers, or more illuminating examples
will be greatly appreciated.

Thanks.
Harold

```

• Prev by Date: Re: How to make the Mathematica Kernel return DisplayPackets?
• Next by Date: Re: Notation for Complex Conjugation
• Previous by thread: RE: How to make the Mathematica Kernel return DisplayPackets?
• Next by thread: Re: Baffled By Underscore Pattern Matching