Re: Named Patterns in Switch
- To: mathgroup at smc.vnet.net
- Subject: [mg48959] Re: [mg48945] Named Patterns in Switch
- From: DrBob <drbob at bigfoot.com>
- Date: Fri, 25 Jun 2004 02:58:26 -0400 (EDT)
- References: <200406240936.FAA28070@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
How's this? foo[expr_]:=expr/.{(a_.)*x^(n_):>a,(a_.)*y^(n_):>n} foo[3*x^3] 3 Bobby On Thu, 24 Jun 2004 05:36:29 -0400 (EDT), David Park <djmp at earthlink.net> wrote: > Dear MathGroup, > > Here is an attempted routine using Switch that does not work. > > foo[expr_] := > Switch[expr, > (a_.)*x^(n_), a, > (a_.)*y^(n_), n] > > foo[3*x^3] > a (I was hoping for 3) > > > Switch uses patterns, but any named patterns are useless. So the a in the third argument in Switch has nothing to do with the a_. in the second argument. > > Is there some Mathematica construction that will test successive patterns with names, do a calculation with the first match and use the names in the patterns? > > David Park > djmp at earthlink.net > http://home.earthlink.net/~djmp/ > > > > -- DrBob at bigfoot.com www.eclecticdreams.net/index.html
- References:
- Named Patterns in Switch
- From: "David Park" <djmp@earthlink.net>
- Named Patterns in Switch