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 1999

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

Search the Archive

Re: Pure Functions in rules

  • To: mathgroup at
  • Subject: [mg16010] Re: Pure Functions in rules
  • From: Paul Abbott <paul at>
  • Date: Sat, 20 Feb 1999 02:52:03 -0500
  • Organization: University of Western Australia
  • References: <7ag34l$>
  • Sender: owner-wri-mathgroup at

Will Self wrote:

> It appears that I cannot depend on using a pure function
> in a pattern-matching rule.

Pure functions are not the problem in your example. (Sometimes you do
need to take care with parens because of the precedence of # and &).

> I am quite frankly incensed by the behavior shown in
> In/Out 80, below. 
> In[80]:=     {1,2,3}/.(m_List->(2*#& /@ m))
> Out[80]=    {1,2,3}

See what happens when you replace -> with :>

	{1, 2, 3} /. m_List :> (2*# & ) /@ m
I think you might now work out what is going on.  The distinction
between -> and :> can be very important but somwhat difficult to
explain. My favorite example to explain the difference between immediate
and delayed replacement is to get the student to compare

	{x,x,x} /. x -> Random[]

 	{x,x,x} /. x :> Random[]

Analogously, to explain the difference between Set and SetDelayed,

	r = Random[];


	r := Random[];


Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia           
Nedlands WA  6907                     mailto:paul at 

            God IS a weakly left-handed dice player

  • Prev by Date: Forms Interface?
  • Next by Date: Re: Strange result of Limit function in Mathematica3.0
  • Previous by thread: Re: Pure Functions in rules
  • Next by thread: Re: Mathematica & Calc Wiz