Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

AW: pattern matching with repeated named patterns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39837] AW: [mg39808] pattern matching with repeated named patterns
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Sat, 8 Mar 2003 02:50:06 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

-----Ursprüngliche Nachricht-----
Von: Wolf, Hartmut 
Gesendet: Freitag, 7. März 2003 16:40
An: 'Gara Kuta'; mathgroup at smc.vnet.net
Betreff: RE: [mg39808] pattern matching with repeated named patterns
[...]



The most simple application might be just to use the pattern as filter for
those records which qualify, or don't:

 
In[31]:= Cases[alist, 
  person : {name_String, sex : M | F, age_Integer, weight_?(1 <= # <= 500
&)}]

Out[31]= {{"Adam", M, 38, 73}, {"Eve", F, 37, 65.5}}


In[33]:= Cases[alist, _?(! 
          MatchQ[#, {name_String, sex : M | F, age_Integer, 
              weight_?(1 <= # <= 500 &)}] &)]

Out[33]= {{"Kain", M, 17, 501}, {Abel, M, 15, 58}}


It's possibly easy to see how I drew myself into that obfuscation, but I
can't let it stay: the right way to do that is (of course!)

In[8]:=
DeleteCases[alist, 
  person : {name_String, sex : M | F, age_Integer, 
      weight_?(1 <= # <= 500 &)}]


Out[8]= {{"Kain", M, 17, 501}, {Abel, M, 15, 58}}


--
Hartmut Wolf



  • Prev by Date: Re: Mathlink problem with number format
  • Next by Date: Re: How to convert string to variable name
  • Previous by thread: EPS margin problem
  • Next by thread: Re: Functional differentiation on the lattice