Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Replace, test question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120341] Re: Replace, test question
  • From: Tomas Garza <tgarza10 at msn.com>
  • Date: Tue, 19 Jul 2011 06:58:14 -0400 (EDT)
  • References: <201107181013.GAA26882@smc.vnet.net>

Look at the syntaxis of PrimeQ. Try
In[5]:= {58, 61, 15, 66, 10, 2, 24, 81, 45, 84} /. x_ / ; PrimeQ[x] -> P
Out[5]= {58, P, 15, 66, 10, P, 24, 81, 45, 84}
-Tomas
> Date: Mon, 18 Jul 2011 06:13:23 -0400
> From: tio540s1 at gmail.com
> Subject: Replace, test question
> To: mathgroup at smc.vnet.net
>
> I'm very new to Mathematica and trying to work my way through it. I
> don't understand why:
> {58, 61, 15, 66, 10, 2, 24, 81, 45, 84} /. x_ /; PrimeQ -> P
> returns:
> {58, 61, 15, 66, 10, 2, 24, 81, 45, 84}
>
> I would expect it to take the list, replace everything in the list
> that matches any pattern and passes the PrimeQ test, i.e., is prime,
> with P to yield:
> {58, P, 15, 66, 10, P, 14, 81, 45, 84}
>
> Can someone explain my misunderstanding?
>
> Thanks.
>
 		 	   		  


  • Prev by Date: Re: Solve never calls Equal?
  • Next by Date: Re: Unexpected Behavior: SetDelayed versus Set
  • Previous by thread: Replace, test question
  • Next by thread: Re: Replace, test question