MathGroup Archive 2010

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

Search the Archive

Re: Re: ReplaceAll reloaded

  • To: mathgroup at
  • Subject: [mg107401] Re: [mg107397] Re: [mg107363] ReplaceAll reloaded
  • From: bsyehuda at
  • Date: Thu, 11 Feb 2010 07:57:50 -0500 (EST)
  • References: <hkeb04$t7v$> <>

you need to prevent the evaluation of Or on a single argument

Or[x] returns x
so in the rhs of the replacement rule Or[y__] returns y__
so the rule itself is identical to Or[a,b] /. y__:> {y}
and the result is clear
two way to solve it

or possibly (for more than 2 variables)

but this is tedious and not a general solution
the way to do it is to prevent the evaluation of the rhs, using HoldPattern

and this returns {a,b}
as required


On Thu, Feb 11, 2010 at 2:08 PM, Leonid Shifrin <lshifr at> wrote:

> Istvan,
> all you need is to run Trace - it shows pretty clearly what happens:
> In[3]:= Or[a,b]/.Or[x__]:>{x}//Trace
> Out[3]= {{{Or[x__],x__},x__:>{x},x__:>{x}},a||b/.x__:>{x},{a||b}}
> <Or> on your pattern evaluates to the pattern itself before the match is
> attempted. This is due
> to the behavior of Or on any single argument - it just returns the
> argument=

  • Prev by Date: Re: manipulate plot
  • Next by Date: Re: Define an antisymmetric function
  • Previous by thread: Re: ReplaceAll reloaded
  • Next by thread: Re: Re: ReplaceAll reloaded