Re: perplexed by blank sequence in pattern replacement
- To: mathgroup at smc.vnet.net
- Subject: [mg68719] Re: [mg68674] perplexed by blank sequence in pattern replacement
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Thu, 17 Aug 2006 04:18:26 -0400 (EDT)
- References: <200608160736.DAA06103@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Aug 16, 2006, at 3:36 AM, Blake wrote: > Dear MathGroup: > > I have been blithely using blank sequences in pattern matching for > some > time. In persuit of a bug in a package of mine, I was quite alarmed to > find that I don't really understand how to use the blank sequence, as > expressed in the following simplified example: > > In[1]:=Replace[a*b*c,Times[mysequence__]:>{mysequence}] > > Out[1]={a b c} > > I expected Out[1]={a,b,c}, from a naieve reading of the full form of > a*b*c > > In[2]:=FullForm[a*b*c] > > Out[2]//FullForm=Times[a,b,c] > > Will someone PLEASE tell me why In[1] does not yield the results I > expected? Because Times has the attribute OneIdentity so Times[a_] -> a always. The second part to the explanation is that the lefthand side of the transformation rule gets evaluated, you can see this if you examine the trace. You need to wrap Times[mysequence__] in a HoldPattern. Regards, Ssezi
- References:
- perplexed by blank sequence in pattern replacement
- From: "Blake" <laing@ou.edu>
- perplexed by blank sequence in pattern replacement