       Pure Functions in rules

• To: mathgroup at smc.vnet.net
• Subject: [mg15932] Pure Functions in rules
• From: wself at viking.emcmt.edu (Will Self)
• Date: Wed, 17 Feb 1999 23:34:01 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```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:=     {1,2,3}/.(m_List->7)
Out=    7

In:=     {1,2,3}/.(m_List->(2*m))
Out=    {2,4,6}

In:=     2*#& /@ {1,2,3}
Out=    {2,4,6}

In:=     f[m_List]:=2*#& /@ m

In:=     f[{1,2,3}]
Out=    {2,4,6}

In:=     {1,2,3}/.m_List->f[m]
Out=    {2,4,6}

Now try this:

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

Does anyone (say, at WRI for example) care to comment on
this?

Will Self

```

• Prev by Date: implementing a stack
• Next by Date: Re: Mathematica & Calc Wiz
• Previous by thread: Re: implementing a stack
• Next by thread: Re: Pure Functions in rules