MathGroup Archive 2007

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

Search the Archive

Re: The uses of Condition (/;)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82957] Re: The uses of Condition (/;)
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Mon, 5 Nov 2007 04:56:55 -0500 (EST)
  • References: <fghcbl$k9n$1@smc.vnet.net> <fgk9sk$pmk$1@smc.vnet.net>

magma wrote:
> Changing slightly topic:
> 
> In the same Condition documentation page we find:
> 
> {6, -7, 3, 2, -1, -2} /. x_ /; x < 0 -> w
> giving
> {6, w, 3, 2, w, w}
> and that 's ok. The x_ stand for the individual elements in the list
> 
> 
> But why then
> {6, -7, 3, 2, -1, -2} /. x_  -> w
> gives
> w
> instead of
> {w,w,w,w,w,w}  ?
> 
> shouldn't the x_ still stand for the individual elements in the list?

This is because x_ matches the complete list {6, -7, 3, 2, -1, -2}.  Try 
x_?NumberQ instead or use a level specification:

Replace[{6, -7, 3, 2, -1, -2}, x_ -> w, {1}]

Szabolcs


  • Prev by Date: How to change the font size in legend
  • Next by Date: Re: NDSolve with functions of vectors
  • Previous by thread: Re: Crash with simple plot command
  • Next by thread: Re: The uses of Condition (/;)