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