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[1]/Out[1] example I understand, but the In[2,3]/Out[3] example (discussed below) has me totally mystified. As printed, we have ... In[2]:= h[a___, x_, b___, x_, c___] := hh[x] h[a, b, c] In[3]:= h[2, 3, 2, 4, 5, 3] Out[3]= h[4, 5] hh[2] hh[3] Now let's make a change to In[2] ... In[4]:= Clear[h, hh] In[5]:= h[a___, x_, b___, x_, c___] := hh[x] h[{a}, {b}, {c}] In[6]:= h[2, 3, 2, 4, 5, 3] Out[6]= h[{}, {3}, {4, 5, 3}] hh[2] 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[5] manipulates the number stream which feeds into it from In[6]. I have no idea of how the In[6] lists came to contain the numbers they do. Any help, pointers to tutorial papers, or more illuminating examples will be greatly appreciated. Thanks. Harold

**Follow-Ups**:**Re: Baffled By Underscore Pattern Matching***From:*"Sseziwa Mukasa,,(978) 536-2359" <mukasa@jeol.com>