RE: RE: Conditional evaluation
- To: mathgroup at smc.vnet.net
- Subject: [mg34332] RE: [mg34290] RE: [mg34281] Conditional evaluation
- From: "DrBob" <majort at cox-internet.com>
- Date: Wed, 15 May 2002 03:35:26 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
In a recent thread we found that when the conditional depends on (or IS) a global variable, the result can be unreliable. It seems to me that Update was used to ameliorate the situation. Bobby Treat -----Original Message----- From: Wolf, Hartmut [mailto:Hartmut.Wolf at t-systems.com] To: mathgroup at smc.vnet.net Subject: [mg34332] [mg34290] RE: [mg34281] Conditional evaluation > -----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: [mg34332] [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