MathGroup Archive 1999

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

Search the Archive

Re: Pure Functions in rules

  • To: mathgroup at
  • Subject: [mg15983] Re: Pure Functions in rules
  • From: "Seth Chandler" <SChandler at>
  • Date: Fri, 19 Feb 1999 03:27:03 -0500
  • Organization: University of Houston
  • References: <7ag34l$>
  • Sender: owner-wri-mathgroup at

If you try {1,2,3}/.(m_List:>(2*#&/.m)) you get the behavior I believe you
desire. Using Rule rather than RuleDelayed causes a problem because, until
there is a specific value of m, Mathematica can't Map the way you want.

Seth J. Chandler
Associate Professor of Law
University of Houston Law Center

Will Self wrote in message <7ag34l$aie at>...
>It appears that I cannot depend on using a pure function
>in a pattern-matching rule.
>Here I am trying to convince reluctant students that they're
>better off learning to use Mathematica than doing things
>by hand, and we run across something like this, and in a
>much more complicated situation where the trouble was
>hard to isolate.
>I am quite frankly incensed by the behavior shown in
>In/Out 80, below.  Look at these examples:
>In[73]:=     {1,2,3}/.(m_List->7)
>Out[73]=    7
>In[74]:=     {1,2,3}/.(m_List->(2*m))
>Out[74]=    {2,4,6}
>In[75]:=     2*#& /@ {1,2,3}
>Out[75]=    {2,4,6}
>In[77]:=     f[m_List]:=2*#& /@ m
>In[78]:=     f[{1,2,3}]
>Out[78]=    {2,4,6}
>In[79]:=     {1,2,3}/.m_List->f[m]
>Out[79]=    {2,4,6}
>Now try this:
>In[80]:=     {1,2,3}/.(m_List->(2*#& /@ m))
>Out[80]=    {1,2,3}
>Does anyone (say, at WRI for example) care to comment on
>Will Self

  • Prev by Date: Re: escape-sequences in strings
  • Next by Date: Re: MyPrependTo
  • Previous by thread: Re: Pure Functions in rules
  • Next by thread: Re: Pure Functions in rules