Strange interaction between local symbols of a proc inside the Initialization of Manipulate with control variables
- To: mathgroup at smc.vnet.net
- Subject: [mg84881] Strange interaction between local symbols of a proc inside the Initialization of Manipulate with control variables
- From: "Nasser Abbasi" <nma at 12000.org>
- Date: Thu, 17 Jan 2008 07:03:35 -0500 (EST)
Mathematica 6.0.1 on windoz. Below are 2 examples. In the first I have a proc in the init of a Manipulate which uses Dynamic symbols to obtain the limits of a plot. (the x and y limits). In the first example, I have ONE local symbol called yy in the proc which is used as the maximum this dynamic symbol goes to. This seems to work ok: (*********** EXAMPLE 1 works ******************) cc=ContinuousAction->False; Manipulate[proc[], {xMax, 10, ControlType -> None}, {yMax, 1, ControlType -> None}, Initialization :> { proc[] := Module[{yy}, yy = 2; Dynamic[Plot[Sin[x], {x, 0, xMax}, PlotRange -> {Automatic, {-yMax, yMax}}, Frame -> True, FrameLabel -> {Slider[Dynamic[xMax], {1, 10},cc], VerticalSlider[Dynamic[yMax], {1, 2*yy},cc]}, RotateLabel -> False ] ] ] } ] Now, I added another local symbol call xx and did the same using it for the x-range. Now I get errors. You'd have to move the slides couple of times to see the error. (********** EXAMPLE 2 error *******************) cc=ContinuousAction->False; Manipulate[proc[], {xMax, 10, ControlType -> None}, {yMax, 1, ControlType -> None}, Initialization :> { proc[] := Module[{yy,xx}, yy = 2; xx = 8; Dynamic[Plot[Sin[x], {x, 0, xMax}, PlotRange -> {Automatic, {-yMax, yMax}}, Frame -> True, FrameLabel -> {Slider[Dynamic[xMax], {1, 2*xx},cc], VerticalSlider[Dynamic[yMax], {1, 2*yy},cc]}, RotateLabel -> False ] ] ] } ] Why would the first example work, and the second not work? I can fix the second example, by making yy and xx localized to Manipulate and not local symbols to the proc[] as follows (********** EXAMPLE 3 works *******************) cc=ContinuousAction->False; Manipulate[proc[], {xMax, 10, ControlType -> None}, {yMax, 1, ControlType -> None}, {yy, 1, ControlType -> None}, {xx, 1, ControlType -> None}, Initialization :> { proc[] := Module[{}, yy = 2; xx = 8; Dynamic[Plot[Sin[x], {x, 0, xMax}, PlotRange -> {Automatic, {-yMax, yMax}}, Frame -> True, FrameLabel -> {Slider[Dynamic[xMax], {1, 2*xx},cc], VerticalSlider[Dynamic[yMax], {1, 2*yy},cc]}, RotateLabel -> False ] ] ] } ] It seems if a local symbol to Manipulate depends on a local symbol to a proc[] 'called' by Manipulate as in the first 2 examples above, this will result in something not nice. But I do not understand why the first example works, and the second does not. It seems adding a second interaction broke something internally by accident? Any idea? And on the subject, could any one be kind enought and summarize what is the visibility scope of a Dynamic symbol in Mathematica? thanks, Nasser