MathGroup Archive 2002

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

Search the Archive

Re: Conditional evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34295] Re: [mg34281] Conditional evaluation
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Tue, 14 May 2002 04:10:06 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On Monday, May 13, 2002, at 05:54 AM, Tim Ebringer wrote:

> 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.
>
>
There is no need to put a conditional expression on the otherwise case 
or the else case when there are only two options.  The definition with a 
conditional is more specific than one without and will be tested first.  
If you are trying to emulate the behavior of If[expr, a, b, c] the three 
definitions:

myFunc[x_]:=a/;expr
myFunc[x_]:=b/;!(expr) (parentheses may be needed to prevent order of 
operations problems)
myFunc[x_]:=c

should work.  I'm not sure what your mean by !expr doesn't evaluate.

Regards,

Ssezi



  • Prev by Date: Re: Conditional evaluation
  • Next by Date: Re: Style of IN[..] and Out[..] names
  • Previous by thread: Re: Conditional evaluation
  • Next by thread: RE: Conditional evaluation