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

Re: pattern matching with repeated named patterns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39916] Re: [mg39808] pattern matching with repeated named patterns
  • From: Omega Consulting <info at omegaconsultinggroup.com>
  • Date: Tue, 11 Mar 2003 02:38:48 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

At 02:42 AM 3/7/2003, Gara Kuta wrote:
>Hi
>I have a list of data records which are all of the same type, for
>example person:{name_Sting, sex:M|F, age_Integer, weight_?((1<#<500)&)}.
>I want to access the different fields so I have given them names in the
>pattern. I have a list of these records and I want to use pattern
>matching to test the the whole list such as
>{person:{name_Sting, sex:M|F, age_Integer, weight_?((1<#<500)&)}...}
>but once you name the parts of the pattern, they have to be the same for
>every record. I could leave the names out and use a pattern like
>{{_Sting, M|F, _Integer, _?((1<#<500)&)}...}
>which matches different records with the same structure but then I can't
>access the field values by name. Is there any way I can do both at once?
>Thanks
>G

How about something like this?

f[people:{{_Sting, M|F, _Integer, _?((1<#<500)&)}...}]:=
Module[{name, sex, age, weight},
   {name, sex, age, weight} = Transpose[people];
   ...
]

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com



  • Prev by Date: Re: Mathlink problem with number format
  • Next by Date: Re: Running ssh in Mathematica
  • Previous by thread: RE: pattern matching with repeated named patterns
  • Next by thread: RE: Tentative conclusion: Mathematica cannot outputplain text