RE: Conditional evaluation
- To: mathgroup at smc.vnet.net
- Subject: [mg34290] RE: [mg34281] Conditional evaluation
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Tue, 14 May 2002 04:09:59 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
> -----Original Message----- > From: Tim Ebringer [mailto:drearyslig at hotmail.com] To: mathgroup at smc.vnet.net > Sent: Monday, May 13, 2002 11:55 AM > Subject: [mg34290] [mg34281] Conditional evaluation > > > Greetings gurus, > > Does anyone know how to do the expression If[expr, a, b, b] using the > conditional /; operation, i.e. > > myFunc[x_]:=a /; expr > myFunc[x_]:=b /; <otherwise> > > I could do it using the If function, but would much prefer, for layout > reasons, to use the conditional operator, but I can't seem to > make it do the > "otherwise" part. Note that !expr doesn't work in this case because it > doesn't evaluate. > > Cheers, > > Tim. > > > Tim, if it is not this... In[1]:= myFunc[x_] := a /; expr myFunc[x_] := b /; ! expr myFunc[x_] := c In[4]:= expr = True; In[5]:= myFunc[True] Out[5]= a In[6]:= expr = False; In[7]:= myFunc[False] Out[7]= b In[8]:= expr =. In[9]:= myFunc[Undefined] Out[9]= c ...you should tell more about expr (Note that you also can use Condition within Module, With, or Block at rhs.) -- Hartmut