Re: Weird localization bug!
- To: mathgroup at smc.vnet.net
- Subject: [mg106044] Re: Weird localization bug!
- From: dh <dh at metrohm.com>
- Date: Thu, 31 Dec 2009 03:15:23 -0500 (EST)
- References: <hhf5pa$h0e$1@smc.vnet.net>
Hi, according to the manual, Rule should evaluate its arguments normally (with the exception of Sequence). Now consider: makerule[input_] := Rule[(input /. a_Integer :> 2 a), input]; Trace@makerule[5] You will see that the first a is localized, the second not. There seems to be a problem with nested rules. I would report this to Wolfram. Daniel On 30 Dez., 10:16, Derek Yates <yat... 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?