MathGroup Archive 1993

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Flat Strings

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: RE: Flat Strings
  • From: withoff
  • Date: Tue, 1 Jun 93 09:58:31 CDT

> I found that with the attribute 
> Flat, FlatString["a","b","c"] was not matching the pattern on the LHS of the 
> definition above.  Interestingly, when I removed "String" from the argument 
> patterns, it DID match!  Mmm.  So I've constructed the following example 
> which certainly seems to illustrate a bug:
> 
> Mathematica 2.1 for NeXT
> Copyright 1988-92 Wolfram Research, Inc.
> 
> In[1]:= Attributes[f] = {};
> 
> In[2]:= MatchQ[ f[1], f[_Integer] ]
> 
> Out[2]= True                          (* Fine. *)
> 
> In[3]:= Attributes[f] = {Flat};
> 
> In[4]:= MatchQ[ f[1], f[_Integer] ]
> 
> Out[4]= False                         (* HUH? *)
> 
> In[5]:= MatchQ[ f[1], f[_] ]
> 
> Out[5]= True                          (* OK, but we need to specify head *)
> 
> ^^^^  How 'bout it WRI, is this a bug or what?  ^^^^

No, this is not a bug, but it is a good demonstration of the
use of OneIdentity.

In[1]:= MatchQ[ f[1], f[_Integer] ]

Out[1]= True

In[2]:= SetAttributes[f, Flat]

In[3]:= MatchQ[ f[1], f[_Integer] ]

Out[3]= False

In[4]:= SetAttributes[f, OneIdentity]

In[5]:= MatchQ[ f[1], f[_Integer] ]

Out[5]= True

Another example can be found on page 232 of the Mathematica book.

Dave Withoff
Wolfram Research













  • Prev by Date: A curious sign error
  • Next by Date: Object Oriented Programming in MMA
  • Previous by thread: Re: Flat Strings
  • Next by thread: citing Mma