Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: ReplaceList -- Unexpected Answer

  • To: mathgroup at
  • Subject: [mg46798] Re: ReplaceList -- Unexpected Answer
  • From: bobhanlon at (Bob Hanlon)
  • Date: Tue, 9 Mar 2004 04:30:41 -0500 (EST)
  • References: <c2hdqc$aeq$>
  • Sender: owner-wri-mathgroup at

ReplaceList "attempts to transform the entire expression".  If instead you want
it applied to the first level subexpressions:

ReplaceList[#,f[x:h[_],x_]->r[x]]& /@ 
    {f[h[4],h[4]],f[h[4],h[5]]} // Flatten


Bob Hanlon

In article <c2hdqc$aeq$1 at>, Harold.Noffke at (Harold
Noffke) wrote:

<< In The Mathematica 5 Book, Section 2.3.3 Naming Pieces of Patterns, we
find the following pattern matching exercise ...

	Now both arguments of f are constrained to be the same, and only the
	first case matches.  

		{f[h[4], h[4]], f[h[4], h[5]]} /. f[x:h[_], x_] -> r[x]

Now, let's use ReplaceList to get more insight into this matching
process ...

		ReplaceList[ {f[h[4],h[4]],f[h[4],h[5]]},f[x:h[_],x_] -> r[x] ]
I do not understand why ReplaceList returns {} instead of { r[h[4]] }.

  • Prev by Date: RE: Problem with Mathematica driving me nuts
  • Next by Date: Re: Problem with Mathematica driving me nuts
  • Previous by thread: Re: ReplaceList -- Unexpected Answer
  • Next by thread: Re: ReplaceList -- Unexpected Answer