Skip to main content
Fixed minor errors
Source Link
JungHwan Min
  • 4.7k
  • 1
  • 23
  • 36

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider:

DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f];
 f[]; Slider[Dynamic[x, f[] &]]]

(* f$400707 *)
(* Slider *)
(* f$$3152 *)

Or, usingf$$3152 is printed when you move the slider.

Using OP's code construction (added a slider in outer for clarity)+ some modifications:

ClearAll[inner, outer];
inner[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update; Print@args);
   update[];
   Slider[Dynamic[x, update[] &]]];
outer[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update);
   update[];
   {Slider[Dynamic[x, update[] &]],
    inner[Dynamic[x, update[] &]]}];
x = 1;
outer[Dynamic@x]

(* update$405810 *)
(* update$405811 *)
(* update$405810[] & *)
(* 2 Sliders *)
(* FE`update$$3176 *)
(* FE`update$$3177 *)
(* FE`update$$3177[] & *)

The 3176 is printed when you move the first slider (outer). The two 3177s are printed when you move the second slider (inner). The first three lines of output is the expected behavior (args refers to update in outer (405810) not inner (405811)), which is correct, but the last three lines are the actual behavior (args refers to update in inner (3177) not outer (3176)).

This creates name confusion as I stated in the first comment, forcingcausing Mathematica to use the definition of update defined by inner for all instances of update.

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider:

DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f];
 f[]; Slider[Dynamic[x, f[] &]]]

(* f$400707 *)
(* Slider *)
(* f$$3152 *)

Or, using OP's code construction (added a slider in outer for clarity):

ClearAll[inner, outer];
inner[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update; Print@args);
   update[];
   Slider[Dynamic[x, update[] &]]];
outer[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update);
   update[];
   {Slider[Dynamic[x, update[] &]],
    inner[Dynamic[x, update[] &]]}];

(* update$405810 *)
(* update$405811 *)
(* update$405810[] & *)
(* 2 Sliders *)
(* FE`update$$3176 *)
(* FE`update$$3177 *)
(* FE`update$$3177[] & *)

The 3176 is printed when you move the first slider (outer). The two 3177s are printed when you move the second slider (inner). The first three lines of output is the expected behavior (args refers to update in outer (405810) not inner (405811)), which is correct, but the last three lines are the actual behavior (args refers to update in inner (3177) not outer (3176)).

This creates name confusion as I stated in the first comment, forcing Mathematica to use the definition of update defined by inner for all instances of update.

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider:

DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f];
 f[]; Slider[Dynamic[x, f[] &]]]

(* f$400707 *)
(* Slider *)
(* f$$3152 *)

f$$3152 is printed when you move the slider.

Using OP's code construction + some modifications:

ClearAll[inner, outer];
inner[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update; Print@args);
   update[];
   Slider[Dynamic[x, update[] &]]];
outer[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update);
   update[];
   {Slider[Dynamic[x, update[] &]],
    inner[Dynamic[x, update[] &]]}];
x = 1;
outer[Dynamic@x]

(* update$405810 *)
(* update$405811 *)
(* update$405810[] & *)
(* 2 Sliders *)
(* FE`update$$3176 *)
(* FE`update$$3177 *)
(* FE`update$$3177[] & *)

The 3176 is printed when you move the first slider (outer). The two 3177s are printed when you move the second slider (inner). The first three lines of output is the expected behavior (args refers to update in outer (405810) not inner (405811)), which is correct, but the last three lines are the actual behavior (args refers to update in inner (3177) not outer (3176)).

This creates name confusion as I stated in the first comment, causing Mathematica to use the definition of update defined by inner for all instances of update.

added 29 characters in body
Source Link
JungHwan Min
  • 4.7k
  • 1
  • 23
  • 36

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider:

DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f];
 f[]; Slider[Dynamic[x, f[] &]]]

(* f$400707 *)
(* Slider *)
(* f$$3152 *)

Or, using OP's code construction (added a slider in outer for clarity):

ClearAll[inner, outer];
inner[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update; Print@args);
   update[];
   Slider[Dynamic[x, update[] &]]];
outer[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update);
   update[];
   {Slider[Dynamic[x, update[] &]],
    inner[Dynamic[x, update[] &]]}];

(* update$405810 *)
(* update$405811 *)
(* update$405810[] & *)
(* 2 Sliders *)
(* FE`update$$3176 *)
(* FE`update$$3177 *)
(* FE`update$$3177[] & *)

The 3176 is printed when you move the first slider (outer). The two 3177s are printed when you move the second slider (inner). The first three lines of output is the expected behavior (args refers to update in outer (405810) not inner (405811)), which is correct, but the last three lines are the actual behavior. The Dynamic (Slider) thinks that args uses the definition ofrefers to update in inner ( (3177)) not outer (outer (3176)).

This creates name confusion as I stated in the first comment, forcing Mathematica to use the definition of update defined by inner for all instances of update.

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider:

DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f];
 f[]; Slider[Dynamic[x, f[] &]]]

(* f$400707 *)
(* Slider *)
(* f$$3152 *)

Or, using OP's code construction:

ClearAll[inner, outer];
inner[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update; Print@args);
   update[];
   Slider[Dynamic[x, update[] &]]];
outer[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update);
   update[];
   {Slider[Dynamic[x, update[] &]],
    inner[Dynamic[x, update[] &]]}];

(* update$405810 *)
(* update$405811 *)
(* update$405810[] & *)
(* 2 Sliders *)
(* FE`update$$3176 *)
(* FE`update$$3177 *)
(* FE`update$$3177[] & *)

The 3176 is printed when you move the first slider (outer). The two 3177s are printed when you move the second slider (inner). The first three lines of output is the expected behavior, but the last three lines are the actual behavior. The Dynamic (Slider) thinks that args uses the definition of update in inner (3177) not outer (3176).

This creates name confusion as I stated in the first comment, forcing Mathematica to use the definition of update defined by inner for all instances of update.

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider:

DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f];
 f[]; Slider[Dynamic[x, f[] &]]]

(* f$400707 *)
(* Slider *)
(* f$$3152 *)

Or, using OP's code construction (added a slider in outer for clarity):

ClearAll[inner, outer];
inner[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update; Print@args);
   update[];
   Slider[Dynamic[x, update[] &]]];
outer[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update);
   update[];
   {Slider[Dynamic[x, update[] &]],
    inner[Dynamic[x, update[] &]]}];

(* update$405810 *)
(* update$405811 *)
(* update$405810[] & *)
(* 2 Sliders *)
(* FE`update$$3176 *)
(* FE`update$$3177 *)
(* FE`update$$3177[] & *)

The 3176 is printed when you move the first slider (outer). The two 3177s are printed when you move the second slider (inner). The first three lines of output is the expected behavior (args refers to update in outer (405810) not inner (405811)), which is correct, but the last three lines are the actual behavior (args refers to update in inner (3177) not outer (3176)).

This creates name confusion as I stated in the first comment, forcing Mathematica to use the definition of update defined by inner for all instances of update.

Clarity + New code
Source Link
JungHwan Min
  • 4.7k
  • 1
  • 23
  • 36

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider:

DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f];
 f[]; Slider[Dynamic[x, f[] &]]]

(* f$400707 *)
(* Slider *)
(* f$$3152 *)

Or, using OP's code construction:

ClearAll[inner, outer];
inner[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update; Print@args);
   update[];
   Slider[Dynamic[x, update[] &]]];
outer[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update);
   update[];
   {Slider[Dynamic[x, update[] &]],
    inner[Dynamic[x, update[] &]]}];

(* update$405810 *)
(* update$405811 *)
(* update$405810[] & *)
(* 2 Sliders *)
(* FE`update$$3176 *)
(* FE`update$$3177 *)
(* FE`update$$3177[] & *)

The 3176 is printed when you move the first slider (outer). The two 3177s are printed when you move the second slider (inner). The first three lines of output is the expected behavior, but the last three lines are the actual behavior. The Dynamic (Slider) thinks that args uses the definition of update in inner (3177) not outer (3176).

This creates name confusion as I stated in the first comment, forcing Mathematica to use the definition of update defined by inner for all instances of update.

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider:

DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f];
 f[]; Slider[Dynamic[x, f[] &]]]

(* f$400707 *)
(* Slider *)
(* f$$3152 *)

This creates name confusion as I stated in the first comment, forcing Mathematica to use the definition of update defined by inner for all instances of update.

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider:

DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f];
 f[]; Slider[Dynamic[x, f[] &]]]

(* f$400707 *)
(* Slider *)
(* f$$3152 *)

Or, using OP's code construction:

ClearAll[inner, outer];
inner[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update; Print@args);
   update[];
   Slider[Dynamic[x, update[] &]]];
outer[Dynamic[x_, args___]] := DynamicModule[{update},
   update[] := (Print@update);
   update[];
   {Slider[Dynamic[x, update[] &]],
    inner[Dynamic[x, update[] &]]}];

(* update$405810 *)
(* update$405811 *)
(* update$405810[] & *)
(* 2 Sliders *)
(* FE`update$$3176 *)
(* FE`update$$3177 *)
(* FE`update$$3177[] & *)

The 3176 is printed when you move the first slider (outer). The two 3177s are printed when you move the second slider (inner). The first three lines of output is the expected behavior, but the last three lines are the actual behavior. The Dynamic (Slider) thinks that args uses the definition of update in inner (3177) not outer (3176).

This creates name confusion as I stated in the first comment, forcing Mathematica to use the definition of update defined by inner for all instances of update.

deleted 25 characters in body
Source Link
JungHwan Min
  • 4.7k
  • 1
  • 23
  • 36
Loading
Source Link
JungHwan Min
  • 4.7k
  • 1
  • 23
  • 36
Loading