Re: scope all wrong? in Mathematica 4.1
- To: mathgroup at smc.vnet.net
- Subject: [mg31887] Re: scope all wrong? in Mathematica 4.1
- From: "Alan Mason" <swt at austin.rr.com>
- Date: Sun, 9 Dec 2001 06:07:12 -0500 (EST)
- References: <9ul2ft$6m3$1@smc.vnet.net> <9uqa42$ah0$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hello All. The following notebook has been instrumented to reveal the origin of the mysterious print statements for Fateman's third example. Looks like Allan Hayes is right -- it seems that evaluation is being triggered in an attempt to sort out possible effects of the previous rules on the one currently being defined. Can WR confirm this and elaborate on just how SetDelayed works? In[1]:= Module[{x}, uu[x_?((Print["Initially, x is ", {x, Hold[x]}];x = 5; Print["x is ", x]; True) &)] := x; Print["in Module, x is " , x]] in Module, x is \[InvisibleSpace]x$9 In[2]:= ?uu Global`uu \!\(\* InterpretationBox[GridBox[{ {GridBox[{ {\(uu[ x_?\((\((Print["Initially, x is ", {x$9, Hold[x$9]}]; x$9 = 5; Print["x is ", x$9]; True)\) &)\)] := x\)} }, GridBaseline->{Baseline, {1, 1}}, ColumnWidths->0.999, ColumnAlignments->{Left}]} }, GridBaseline->{Baseline, {1, 1}}, ColumnAlignments->{Left}], Definition[ "uu"], Editable->False]\) In[3]:= x$9 = 9 Out[3]= 9 In[4]:= Module[{x}, uu[x_?((Print["Initially, x is ", {x, Hold[x]}];x = 5; Print["x is ", x]; True) &)] := x; Print["in Module, x is " , x]] Initially, x is \[InvisibleSpace]{9,Hold[x$9]} x is \[InvisibleSpace]5 Initially, x is \[InvisibleSpace]{x$20,Hold[x$20]} x is \[InvisibleSpace]5 in Module, x is \[InvisibleSpace]5 In[5]:= x$9 Out[5]= 5 In[6]:= ?uu Global`uu \!\(\* InterpretationBox[GridBox[{ {GridBox[{ {\(uu[ x_?\((\((Print["Initially, x is ", {x$9, Hold[x$9]}]; x$9 = 5; Print["x is ", x$9]; True)\) &)\)] := x\)}, {" "}, {\(uu[ x_?\((\((Print["Initially, x is ", {x$20, Hold[x$20]}]; x$20 = 5; Print["x is ", x$20]; True)\) &)\)] := x\)} }, GridBaseline->{Baseline, {1, 1}}, ColumnWidths->0.999, ColumnAlignments->{Left}]} }, GridBaseline->{Baseline, {1, 1}}, ColumnAlignments->{Left}], Definition[ "uu"], Editable->False]\) In[7]:= x$9 = 9;x$20 = 20; In[8]:= Module[{x}, uu[x_?((Print["Initially, x is ", {x, Hold[x]}];x = 5; Print["x is ", x]; True) &)] := x; Print["in Module, x is " , x]] Initially, x is \[InvisibleSpace]{9,Hold[x$9]} x is \[InvisibleSpace]5 Initially, x is \[InvisibleSpace]{x$24,Hold[x$24]} x is \[InvisibleSpace]5 Initially, x is \[InvisibleSpace]{20,Hold[x$20]} x is \[InvisibleSpace]5 Initially, x is \[InvisibleSpace]{5,Hold[x$24]} x is \[InvisibleSpace]5 in Module, x is \[InvisibleSpace]5 In[9]:= ?uu Global`uu \!\(\* InterpretationBox[GridBox[{ {GridBox[{ {\(uu[ x_?\((\((Print["Initially, x is ", {x$9, Hold[x$9]}]; x$9 = 5; Print["x is ", x$9]; True)\) &)\)] := x\)}, {" "}, {\(uu[ x_?\((\((Print["Initially, x is ", {x$20, Hold[x$20]}]; x$20 = 5; Print["x is ", x$20]; True)\) &)\)] := x\)}, {" "}, {\(uu[ x_?\((\((Print["Initially, x is ", {x$24, Hold[x$24]}]; x$24 = 5; Print["x is ", x$24]; True)\) &)\)] := x\)} }, GridBaseline->{Baseline, {1, 1}}, ColumnWidths->0.999, ColumnAlignments->{Left}]} }, GridBaseline->{Baseline, {1, 1}}, ColumnAlignments->{Left}], Definition[ "uu"], Editable->False]\) In[10]:= x$9 = 9;x$20 = 20;x$24=24; In[11]:= Module[{x}, uu[x_?((Print["Initially, x is ", {x, Hold[x]}];x = 5; Print["x is ", x]; True) &)] := x; Print["in Module, x is " , x]] Initially, x is \[InvisibleSpace]{9,Hold[x$9]} x is \[InvisibleSpace]5 Initially, x is \[InvisibleSpace]{x$28,Hold[x$28]} x is \[InvisibleSpace]5 Initially, x is \[InvisibleSpace]{20,Hold[x$20]} x is \[InvisibleSpace]5 Initially, x is \[InvisibleSpace]{5,Hold[x$28]} x is \[InvisibleSpace]5 Initially, x is \[InvisibleSpace]{24,Hold[x$24]} x is \[InvisibleSpace]5 Initially, x is \[InvisibleSpace]{5,Hold[x$28]} x is \[InvisibleSpace]5 in Module, x is \[InvisibleSpace]5