Re: Named Patterns in Switch
- To: mathgroup at smc.vnet.net
- Subject: [mg48948] Re: Named Patterns in Switch
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 25 Jun 2004 02:58:12 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <cbe8ta$svc$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi, foo[expr_] := expr /. {(a_.)*x^(n_) :> a, (a_.)*y^(n_) :> n} ?????? ??????? Regards Jens David Park 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/