Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg16001] Re: [mg15932] Pure Functions in rules
  • From: BobHanlon at aol.com
  • Date: Fri, 19 Feb 1999 03:27:12 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2/18/99 5:39:37 AM, wself at viking.emcmt.edu writes:

>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:
>
[deleted examples]
>
>Now try this:
>
>In[80]:=     {1,2,3}/.(m_List->(2*#& /@ m))
>Out[80]=    {1,2,3}
>

Will,

You need to use RuleDelayed vice Rule.

{1,2,3}/.(m_List:>(2*#& /@ m))

{2,4,6}

Bob Hanlon


  • Prev by Date: Re: implementing a stack
  • Next by Date: Re: MyPrependTo
  • Previous by thread: Pure Functions in rules
  • Next by thread: Re: Pure Functions in rules