MathGroup Archive 2004

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

Search the Archive

Named Patterns in Switch


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/ 




  • Prev by Date: Re: faster sublist checking
  • Next by Date: Re: basic question about plotting 2 functions in one graph
  • Previous by thread: Periodic Table of Elements (Chemistry)
  • Next by thread: Re: Named Patterns in Switch