Re: Scoping constructs Block, Module, ModuleBlock violate
- To: mathgroup at smc.vnet.net
- Subject: [mg111301] Re: Scoping constructs Block, Module, ModuleBlock violate
- From: John Fultz <jfultz at wolfram.com>
- Date: Tue, 27 Jul 2010 04:15:26 -0400 (EDT)
On Mon, 26 Jul 2010 11:06:56 -0700, Michael wrote: > On 7/22/2010 2:42 AM, John Fultz wrote: >> [...] >> I didn't look at your original code, but I think I probably know why >> your use of >> Block and Dynamic together failed. The principal point is that Block >> introduces >> an environment where variables can be temporarily redefined, but that >> environment evaporates the moment Block is finished evaluating. The >> contents of >> a Dynamic never even begin evaluating until well after the Shift-Enter >> evaluation is over. >> [...] >> > Hi again John, > > I'm seeing a similar thing happen when I use DynamicModule: > > xyz == "A"; > f[] :== DynamicModule[{tmp == "A"}, > CreateDialog[{ > PopupMenu[Dynamic[tmp], {"A", "B", "C", "D"}], > PopupMenu[Dynamic[xyz], {"A", "B", "C", "D"}] > }] > ]; > Button["Test", f[]] > > If I click on the "Test" button, I don't see the value of "tmp" being > changed when I pick different options from the pop up menu, but I *do* > see the value of "xyz" being changed when I pick different options from > its pop up menu. > > However, if I execute f[] directly, it works for both cases. Shouldn't > clicking the button produce identical results to calling whatever is > defined for its action? There seems to be something related to using a > dynamic module variable, perhaps it loses its definition during a Button > call or something. > >> Sincerely, >> >> John Fultz >> jfultz at wolfram.com >> User Interface Group >> Wolfram Research, Inc. >> > > Best Regards, > > Michael You need to read up on DynamicModule wormholes. In the help viewer, type: tutorial/AdvancedDynamicFunctionality and DynamicModule wormholes are the very last topic. However, they're also the very most advanced. You really should read the both the introductory tutorial here... tutorial/IntroductionToDynamic and the advanced tutorial, in their entirety, in sequence. Doing so will help you to understand both why the above failure happens and the best method for resolving it. Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc.