|
[Date Index]
[Thread Index]
[Author Index]
Re: Named Patterns in Switch
- To: mathgroup at smc.vnet.net
- Subject: [mg48969] Re: [mg48945] Named Patterns in Switch
- From: Yasvir Tesiram <tesiramy at omrf.ouhsc.edu>
- Date: Fri, 25 Jun 2004 02:58:44 -0400 (EDT)
- References: <200406240936.FAA28070@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi David,
Does the following do what you want for all general cases?
In[14]:= f1=3*x^3
In[23]:= f2=3*y^6
In[21]:= foo[expr_]:=Switch[expr,(a_.)*x^(n_), expr[[1]],
(a_.)*y^(n_),expr[[2]][[2]]]
In[22]:= foo[f1]
Out[22]= 3
In[24]:= foo[f2]
Out[24]= 6
Regards
Yas
On Thu, 24 Jun 2004, 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/
>
>
>
Prev by Date:
Re: Named Patterns in Switch
Next by Date:
Re: Named Patterns in Switch
Previous by thread:
Re: Named Patterns in Switch
Next by thread:
Re: Named Patterns in Switch
|