MathGroup Archive 2009

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

Search the Archive

Re: Weird localization bug!

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106070] Re: [mg106009] Weird localization bug!
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 31 Dec 2009 03:20:21 -0500 (EST)
  • Reply-to: hanlonr at cox.net

Perhaps one of these is what you want

Clear[makerule]

makerule[input_Integer] :=
 2*input -> input

makerule /@ {5, 5 x}

{10->5,makerule(5 x)}

Clear[makerule]

makerule[input_] :=
 input /. a_Integer :> (2 a -> a)

makerule /@ {5, 5 x}

{10->5,x (10->5)}


Bob Hanlon

---- Derek Yates <yatesd at mac.com> wrote: 

=============
I can't figure this out, and think it is a bug. I'm using Mathematica
7.0.0 and get the same behaviour on both Mac OS X (10.5.8) and on
Windows XP.

I want a function which creates a rule. The rule is of the form
"manipulated input" -> "input". Here is my first attempt (I have
simplified from what I really want to do, in order to illustrate the
bug):

(1) makerule[input_] :=(input /. a_Integer :> 2 a) -> input
In: makerule[5]
Out: 2a->5

(I expect to get 10->5)

(2) makerule2[input_] := (input /. a_Integer :> 2 a)~myrule~input
In: makerule2[5]
Out: myrule[10,5]

as expected

Forcing an extra layer of localization seems to squash the bug:

(3) makerule3[input_] :=Block[{inputcopy = input},(input /.
a_Integer :> 2 a) -> inputcopy]
In: makerule[5]
Out: 10->5

Is it a bug, or have I misunderstood how the localization is meant to
work?




  • Prev by Date: Re: More /.{I->-1} craziness
  • Next by Date: Re: Persistent assumption
  • Previous by thread: Re: Weird localization bug!
  • Next by thread: Re: Weird localization bug!