MathGroup Archive 2008

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

Search the Archive

Re: Parameter conditions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88665] Re: [mg88656] Parameter conditions
  • From: "W_Craig Carter" <ccarter at mit.edu>
  • Date: Mon, 12 May 2008 04:43:57 -0400 (EDT)
  • References: <200805111916.PAA08930@smc.vnet.net>

Hello Steve,
?test has to yield true or false on its argument.

Does this make sense?

happy[p_?PrimeQ] := 100;
happy[p_?(Not[PrimeQ[#]] &)] := 200;
happy[4]
happy[5]
happy[goLucky]

Note the ":=" and also "/;" might be useful to you
Craig

>Steven Siew <siewsk at bp.com> wrote:
> I'm just curious why the simple code below is not working.
>
>  Why is happy[4] not returning the number 200
>
>
>  In[1]:=  happy[p_?PrimeQ] = 100;
>            happy[p_?Not[PrimeQ]] = 200;
>
>  In[3]:=  Inhappy[4]
>  Out[3]:= happy[4]
>
>  In[4]:=  happy[5]
>  Out[4]:=  100
>
>



-- 
W. Craig Carter


  • Prev by Date: Null Return for a Module
  • Next by Date: Re: Parameter conditions
  • Previous by thread: Parameter conditions
  • Next by thread: Re: Parameter conditions