From: István on
Thank you for the extensive help.
For those who are interested, and could not see the replies I got
(*OFF* I still don't understand fully the posting behaviour of this
interface: I got at least 4 emails, but none of them shows up in the
web interface. If I reply to the emails, then I assume no post will
show up in the group's archive. Therefore I always post using the web
inteface. Is there a better way to do this? *ON*), I will recapitulate
the solution.
The "assign" and "initialize" functions should be defined with
DownValues instead of OwnValues, that is:

assign[]:=(...) instead of assign:=(...),

although the fact that simply OwnValues won't work here goes against
my intuition. Also it is not clear (although Ariel shed some light on
it) what is the exact difference between calling the functions assign
[] and initialize[] at the end of the Initialization option or at the
start of DynamicModule, right after defining local variables:

DynamicModule[{assign,x,y},(*dynamic expression to
show*),Initialization:>(assign[]:=(y=x);assign[]a)]
vs.
DynamicModule[{assign,x,y},assign[];(*dynamic expression to
show*),Initialization:>(assign[]:=(y=x))]


Furthermore, Norbert has pointed out, that my model can be further
simlified to this:

DynamicModule[{something},1,Initialization:>(something:=(Print["you
should never see this!"]);)]

returning 1, and the string is printed as well, which effectively
demonstrates, that DynamicModule evaluates even those expressions,
which shouldn't be evaluated. Unfortunately, this example, and the
following one (still from Norbert) completely freezes my Mathematica
7.0 (I have to kill it from TaskManager), so I can't even confirm.
Anyone else has problems evaluating these examples, or you all can run
them as Norbert does?

DynamicModule[{x=False,something,i=0},{
RadioButton[Dynamic[x,(x=#)&],True],
RadioButton[Dynamic[x],False],
Dynamic[i]},
Initialization:>(something:=(Print["init",i++]))

From: DrMajorBob on
> As you can see, DynamicModule evaluates its variables, even though I
> wouldn't expect it to do it. Is there anything about it in the
> documentation?

Look at, for instance, the first two examples on the Help page for
Initialization:

Specify an expression to be evaluated before displaying Dynamic:
Dynamic[c[1],Initialization:>(c[x_]:={x})]
{1}

DynamicModule:
DynamicModule[{c},Dynamic[c[1]],Initialization:>(c[x_]:={x})]
{1}

Bobby

On Wed, 20 Jan 2010 05:50:36 -0600, Norbert P. <bertapozar(a)gmail.com>
wrote:

> Hi Istv=E1n,
>
> this is one of the weird behaviors of DynamicModule. The dynamic
> functionality is awesome, but I find it very hard to create a more
> involved interface due to the unpredictability of the components. More
> involved means anything more than the simple demos from
> demonstrations.wolfram.com. Even though the documentation is quite
> extensive, many details are missing.
>
> I was staring at your code for quite a while =) It turns out that it
> still contains a lot of clutter. You could've stripped most of it and
> you'd get:
>
> In[1]:=
> DynamicModule[{something},
> 1,
> Initialization:>(something:=(Print["you should never see this!"]);)
> ]
> Out[1]= 1
> During evaluation of In[1]:= you should never see this!
>
> As you can see, DynamicModule evaluates its variables, even though I
> wouldn't expect it to do it. Is there anything about it in the
> documentation?
>
> The solution for you is to define functions not as OwnValues as above,
> but as DownValues, as in:
>
> In[2]:= DynamicModule[{something},
> 1,
> Initialization:>(something[]:=(Print["you should never see
> this!"]);)
> ]
> Out[2]= 1
>
> In this case, something doesn't get evaluated and it works the way you
> expect. So try
>
> Panel(a)DynamicModule[{x,y,assign,initialize},Grid[{{"","A","B"},{"w/
> assign:",RadioButton[Dynamic[x,(x=#;assign[])&],True],RadioButton
> [Dynamic[x,(x=#;assign[])&],False]},{"w/o assign:",RadioButton
> [Dynamic@x,True],RadioButton[Dynamic@x,False]},
> {"value:",Dynamic@x}},Dividers->{False,
> {False,True,True,True,False}},Alignment->{Left,
> {Center}}],Initialization:>(assign[]:=(y=x);(*further variables to
> update*)initialize[]:=(x=True;assign[]);(*initialization function*)
> initialize[];)]
>
> For some reason, DynamicModule evaluates its variables whenever I
> assign to x as in the following code by clicking the first radio
> button (it evaluates it twice!!), but not when I press the second:
>
> DynamicModule[{x=False,something,i=0},
> {RadioButton[Dynamic[x,(x=#)&],True],RadioButton[Dynamic
> [x],False],Dynamic[i]},Initialization:>(something:=(Print["init",i+
> +]))]
>
> It would be great to hear from someone who knows more about the
> internal working of DynamicModule. My all-time favourite bug is:
>
> In[3]:= DynamicModule[{x=Sequence[]},1]
> During evaluation of In[3]:= Transpose::nmtx: The first two levels of
> the one-dimensional list {{Hold[x]},{}} cannot be transposed. >>
> Out[3]= Manipulate`Dump`eDynamicModule[Transpose
> [Manipulate`Dump`heldsetting[{{Hold[x]},{}}]],1,DynamicModuleValues:>
> {}]
>
> Compare that to ordinary module:
>
> In[4]:= Module[{x=Sequence[]},1]
> Out[4]= 1
>
> I discovered it a couple days after buying Mathematica 6, still
> excited about the new dynamic functionality. That was pretty
> disappointing;)
>
> Best,
> Norbert
>
> On Jan 19, 2:16 am, Istv=E1n <replicator...(a)gmail.com> wrote:
>> Dear Group,
>>
>> I have some problem with a complex interface inside a DynamicModule.
>> This is a toy version of the program, which can fully reproduce the
>> malfunction:
>>
>> Panel(a)DynamicModule[
>> {x, y, assign, initialize},
>>
>> Grid[{
>> {"", "A", "B"},
>> {"w/ assign:", RadioButton[Dynamic[x, (x = #; assign) &], True]=
> ,
>> RadioButton[Dynamic[x, (x = #; assign) &], False]},
>> {"w/o assign:", RadioButton[Dynamic@x, True],
>> RadioButton[Dynamic@x, False]},
>> {"value:", Dynamic@x}
>> }, Dividers -> {False, {False, True, True, True, False}},
>> Alignment -> {Left, {Center}}],
>>
>> Initialization :> (
>> assign := (y = x);(* further variables to update *)
>> initialize := (x = True; assign); (* initialization function =
> *)
>> initialize;
>> )
>> ]
>>
>> Now for some reason, the radiobuttons do not function as intended (at
>> least as I want).
>> The following clicking orders do not work:
>>
>> [w/ + B] then [w/ + A]
>> [w/o + B] then [w/ + A]
>>
>> these work correctly:
>>
>> [w/ + B] then [w/o + A]
>> [w/o + B] then [w/o + A]
>>
>> I guess, that the problem is with the "initialize" (or the "assign")
>> function. Any idea?
>> Thanks in advance
>>
>> Istv=E1n
>
>


--
DrMajorBob(a)yahoo.com

From: Patrick Scheibe on
Hi,

> As far as I can tell, y isn't used or displayed in these solutions
> and isn't defined outside the panel, so what's all that "assign"
> gyration about?

yes, but that's not of interest for the problem. Even if you do
display the stuff it doesn't work and
I assume the example was just an artificial minimal one.

DynamicModule[{x, y, assign},
assign := (y = x);
Column[{
Checkbox[Dynamic[x, (x = #; assign;) &], {True, False}],
Dynamic[{x, y}]
}
], Initialization :> (x = True; assign)
]

DynamicModule[{x, y, assign},
assign[] := (y = x);
Column[{
Checkbox[Dynamic[x, (x = #; assign[];) &], {True, False}],
Dynamic[{x, y}]
}
], Initialization :> (x = True; assign[])
]

Cheers
Patrick


> Bobby
>
> On Wed, 20 Jan 2010 05:46:01 -0600, Patrick Scheibe =
<pscheibe(a)trm.uni-leipzig.de
> > wrote:
>
>> Hi,
>>
>> it matters that your assign and initialize functions have DownValues.
>>
>> Panel(a)DynamicModule[{x, y, assign, initialize},
>> Grid[{{"", "A", "B"}, {"w/ assign:",
>> RadioButton[Dynamic[x, (x = #; assign[]) &], True],
>> RadioButton[Dynamic[x, (x = #; assign[]) &],
>> False]}, {"w/o assign:", RadioButton[Dynamic@x, True],
>> RadioButton[Dynamic@x, False]}, {"value:", Dynamic@x}},
>> Dividers -> {False, {False, True, True, True, False}},
>> Alignment -> {Left, {Center}}],
>> Initialization :> (assign[] := (y =
>> x);(*further variables to update*)
>> initialize[] := (x = True; assign[]);(*initialization =
function*)
>> initialize[];)]
>>
>> Cheers
>> Patrick
>>
>>
>> On Tue, 2010-01-19 at 05:14 -0500, Istv=C3=A1n wrote:
>>> Dear Group,
>>>
>>> I have some problem with a complex interface inside a DynamicModule.
>>> This is a toy version of the program, which can fully reproduce the
>>> malfunction:
>>>
>>> Panel(a)DynamicModule[
>>> {x, y, assign, initialize},
>>>
>>> Grid[{
>>> {"", "A", "B"},
>>> {"w/ assign:", RadioButton[Dynamic[x, (x = #; assign) &], =
True],
>>> RadioButton[Dynamic[x, (x = #; assign) &], False]},
>>> {"w/o assign:", RadioButton[Dynamic@x, True],
>>> RadioButton[Dynamic@x, False]},
>>> {"value:", Dynamic@x}
>>> }, Dividers -> {False, {False, True, True, True, False}},
>>> Alignment -> {Left, {Center}}],
>>>
>>> Initialization :> (
>>> assign := (y = x);(* further variables to update *)
>>> initialize := (x = True; assign); (* initialization function =
*)
>>> initialize;
>>> )
>>> ]
>>>
>>> Now for some reason, the radiobuttons do not function as intended =

>>> (at
>>> least as I want).
>>> The following clicking orders do not work:
>>>
>>> [w/ + B] then [w/ + A]
>>> [w/o + B] then [w/ + A]
>>>
>>> these work correctly:
>>>
>>> [w/ + B] then [w/o + A]
>>> [w/o + B] then [w/o + A]
>>>
>>> I guess, that the problem is with the "initialize" (or the "assign")
>>> function. Any idea?
>>> Thanks in advance
>>>
>>> Istv=E1n
>>>
>>
>>
>
>
> --
> DrMajorBob(a)yahoo.com
>


From: Norbert Pozar on
Hi Bobby,

but that's not quite the same thing. Yes, I expect Initialization
expression to be evaluated before displaying Dynamic. But if you look
carefully at my example, the expression is

SetDelayed[something, Print["you should never see this!"]]

So I expect, when this expression gets evaluated, that simply
"something" has OwnValues containing Print["you should never see
this!"], but the Print command doesn't get evaluated until I
explicitly evaluate the "something" Symbol. This is not what happens
with DynamicModule, because DynamicModule evaluates the symbols
internally. That can be quite surprising, if the symbols have side
effects.

Best,
Norbert

On Wed, Jan 20, 2010 at 10:34 AM, DrMajorBob <btreat1(a)austin.rr.com> wrote:
>> As you can see, DynamicModule evaluates its variables, even though I
>> wouldn't expect it to do it. Is there anything about it in the
>> documentation?
>
> Look at, for instance, the first two examples on the Help page for
> Initialization:
>
> Specify an expression to be evaluated before displaying Dynamic:
> Dynamic[c[1],Initialization:>(c[x_]:={x})]
> {1}
>
> DynamicModule:
> DynamicModule[{c},Dynamic[c[1]],Initialization:>(c[x_]:={x})]
> {1}
>
> Bobby
>
> On Wed, 20 Jan 2010 05:50:36 -0600, Norbert P. <bertapozar(a)gmail.com> wro=
te:
>
>> Hi Istv=E1n,
>>
>> this is one of the weird behaviors of DynamicModule. The dynamic
>> functionality is awesome, but I find it very hard to create a more
>> involved interface due to the unpredictability of the components. More
>> involved means anything more than the simple demos from
>> demonstrations.wolfram.com. Even though the documentation is quite
>> extensive, many details are missing.
>>
>> I was staring at your code for quite a while =) It turns out that it
>> still contains a lot of clutter. You could've stripped most of it and
>> you'd get:
>>
>> In[1]:=
>> DynamicModule[{something},
>> 1,
>> Initialization:>(something:=(Print["you should never see this!"]);)
>> ]
>> Out[1]= 1
>> During evaluation of In[1]:= you should never see this!
>>
>> As you can see, DynamicModule evaluates its variables, even though I
>> wouldn't expect it to do it. Is there anything about it in the
>> documentation?
>>
>> The solution for you is to define functions not as OwnValues as above,
>> but as DownValues, as in:
>>
>> In[2]:= DynamicModule[{something},
>> 1,
>> Initialization:>(something[]:=(Print["you should never see
>> this!"]);)
>> ]
>> Out[2]= 1
>>
>> In this case, something doesn't get evaluated and it works the way you
>> expect. So try
>>
>> Panel(a)DynamicModule[{x,y,assign,initialize},Grid[{{"","A","B"},{"w/
>> assign:",RadioButton[Dynamic[x,(x=#;assign[])&],True],RadioButton
>> [Dynamic[x,(x=#;assign[])&],False]},{"w/o assign:",RadioButton
>> [Dynamic@x,True],RadioButton[Dynamic@x,False]},
>> {"value:",Dynamic@x}},Dividers->{False,
>> {False,True,True,True,False}},Alignment->{Left,
>> {Center}}],Initialization:>(assign[]:=(y=x);(*further variables to
>> update*)initialize[]:=(x=True;assign[]);(*initialization function*)
>> initialize[];)]
>>
>> For some reason, DynamicModule evaluates its variables whenever I
>> assign to x as in the following code by clicking the first radio
>> button (it evaluates it twice!!), but not when I press the second:
>>
>> DynamicModule[{x=False,something,i=0},
>> {RadioButton[Dynamic[x,(x=#)&],True],RadioButton[Dynamic
>> [x],False],Dynamic[i]},Initialization:>(something:=(Print["init",i+
>> +]))]
>>
>> It would be great to hear from someone who knows more about the
>> internal working of DynamicModule. My all-time favourite bug is:
>>
>> In[3]:= DynamicModule[{x=Sequence[]},1]
>> During evaluation of In[3]:= Transpose::nmtx: The first two levels of
>> the one-dimensional list {{Hold[x]},{}} cannot be transposed. >>
>> Out[3]= Manipulate`Dump`eDynamicModule[Transpose
>> [Manipulate`Dump`heldsetting[{{Hold[x]},{}}]],1,DynamicModuleValues:>
>> {}]
>>
>> Compare that to ordinary module:
>>
>> In[4]:= Module[{x=Sequence[]},1]
>> Out[4]= 1
>>
>> I discovered it a couple days after buying Mathematica 6, still
>> excited about the new dynamic functionality. That was pretty
>> disappointing;)
>>
>> Best,
>> Norbert
>>
>> On Jan 19, 2:16 am, Istv=E1n <replicator...(a)gmail.com> wrote:
>>>
>>> Dear Group,
>>>
>>> I have some problem with a complex interface inside a DynamicModule.
>>> This is a toy version of the program, which can fully reproduce the
>>> malfunction:
>>>
>>> Panel(a)DynamicModule[
>>> {x, y, assign, initialize},
>>>
>>> Grid[{
>>> {"", "A", "B"},
>>> {"w/ assign:", RadioButton[Dynamic[x, (x = #; assign) &], True=
]=
>>
>> ,
>>>
>>> RadioButton[Dynamic[x, (x = #; assign) &], False]},
>>> {"w/o assign:", RadioButton[Dynamic@x, True],
>>> RadioButton[Dynamic@x, False]},
>>> {"value:", Dynamic@x}
>>> }, Dividers -> {False, {False, True, True, True, False}},
>>> Alignment -> {Left, {Center}}],
>>>
>>> Initialization :> (
>>> assign := (y = x);(* further variables to update *)
>>> initialize := (x = True; assign); (* initialization function=
=
>>
>> *)
>>>
>>> initialize;
>>> )
>>> ]
>>>
>>> Now for some reason, the radiobuttons do not function as intended (at
>>> least as I want).
>>> The following clicking orders do not work:
>>>
>>> [w/ + B] then [w/ + A]
>>> [w/o + B] then [w/ + A]
>>>
>>> these work correctly:
>>>
>>> [w/ + B] then [w/o + A]
>>> [w/o + B] then [w/o + A]
>>>
>>> I guess, that the problem is with the "initialize" (or the "assign")
>>> function. Any idea?
>>> Thanks in advance
>>>
>>> Istv=E1n
>>
>>
>
>
> --
> DrMajorBob(a)yahoo.com
>

From: DrMajorBob on
Yes, I see the difference now.

> So I expect, when this expression gets evaluated, that simply
> "something" has OwnValues containing Print["you should never see
> this!"], but the Print command doesn't get evaluated until I
> explicitly evaluate the "something" Symbol.

But, apparently, your expectation is wrong.

It looks as if "something" is not only defined by the Initialization
construct, but it's also evaluated at some point. Why, I don't know.

Perhaps it's part of saving the value for a possible later opening of the
same notebook.

Bobby

On Wed, 20 Jan 2010 13:10:26 -0600, Norbert Pozar <bertapozar(a)gmail.com>
wrote:

> Hi Bobby,
>
> but that's not quite the same thing. Yes, I expect Initialization
> expression to be evaluated before displaying Dynamic. But if you look
> carefully at my example, the expression is
>
> SetDelayed[something, Print["you should never see this!"]]
>
> So I expect, when this expression gets evaluated, that simply
> "something" has OwnValues containing Print["you should never see
> this!"], but the Print command doesn't get evaluated until I
> explicitly evaluate the "something" Symbol. This is not what happens
> with DynamicModule, because DynamicModule evaluates the symbols
> internally. That can be quite surprising, if the symbols have side
> effects.
>
> Best,
> Norbert
>
> On Wed, Jan 20, 2010 at 10:34 AM, DrMajorBob <btreat1(a)austin.rr.com>
> wrote:
>>> As you can see, DynamicModule evaluates its variables, even though I
>>> wouldn't expect it to do it. Is there anything about it in the
>>> documentation?
>>
>> Look at, for instance, the first two examples on the Help page for
>> Initialization:
>>
>> Specify an expression to be evaluated before displaying Dynamic:
>> Dynamic[c[1],Initialization:>(c[x_]:={x})]
>> {1}
>>
>> DynamicModule:
>> DynamicModule[{c},Dynamic[c[1]],Initialization:>(c[x_]:={x})]
>> {1}
>>
>> Bobby
>>
>> On Wed, 20 Jan 2010 05:50:36 -0600, Norbert P. <bertapozar(a)gmail.com>
>> wrote:
>>
>>> Hi Istv=E1n,
>>>
>>> this is one of the weird behaviors of DynamicModule. The dynamic
>>> functionality is awesome, but I find it very hard to create a more
>>> involved interface due to the unpredictability of the components. More
>>> involved means anything more than the simple demos from
>>> demonstrations.wolfram.com. Even though the documentation is quite
>>> extensive, many details are missing.
>>>
>>> I was staring at your code for quite a while =) It turns out that it
>>> still contains a lot of clutter. You could've stripped most of it and
>>> you'd get:
>>>
>>> In[1]:=
>>> DynamicModule[{something},
>>> 1,
>>> Initialization:>(something:=(Print["you should never see this!"]);)
>>> ]
>>> Out[1]= 1
>>> During evaluation of In[1]:= you should never see this!
>>>
>>> As you can see, DynamicModule evaluates its variables, even though I
>>> wouldn't expect it to do it. Is there anything about it in the
>>> documentation?
>>>
>>> The solution for you is to define functions not as OwnValues as above,
>>> but as DownValues, as in:
>>>
>>> In[2]:= DynamicModule[{something},
>>> 1,
>>> Initialization:>(something[]:=(Print["you should never see
>>> this!"]);)
>>> ]
>>> Out[2]= 1
>>>
>>> In this case, something doesn't get evaluated and it works the way you
>>> expect. So try
>>>
>>> Panel(a)DynamicModule[{x,y,assign,initialize},Grid[{{"","A","B"},{"w/
>>> assign:",RadioButton[Dynamic[x,(x=#;assign[])&],True],RadioButton
>>> [Dynamic[x,(x=#;assign[])&],False]},{"w/o assign:",RadioButton
>>> [Dynamic@x,True],RadioButton[Dynamic@x,False]},
>>> {"value:",Dynamic@x}},Dividers->{False,
>>> {False,True,True,True,False}},Alignment->{Left,
>>> {Center}}],Initialization:>(assign[]:=(y=x);(*further variables to
>>> update*)initialize[]:=(x=True;assign[]);(*initialization function*)
>>> initialize[];)]
>>>
>>> For some reason, DynamicModule evaluates its variables whenever I
>>> assign to x as in the following code by clicking the first radio
>>> button (it evaluates it twice!!), but not when I press the second:
>>>
>>> DynamicModule[{x=False,something,i=0},
>>> {RadioButton[Dynamic[x,(x=#)&],True],RadioButton[Dynamic
>>> [x],False],Dynamic[i]},Initialization:>(something:=(Print["init",i+
>>> +]))]
>>>
>>> It would be great to hear from someone who knows more about the
>>> internal working of DynamicModule. My all-time favourite bug is:
>>>
>>> In[3]:= DynamicModule[{x=Sequence[]},1]
>>> During evaluation of In[3]:= Transpose::nmtx: The first two levels of
>>> the one-dimensional list {{Hold[x]},{}} cannot be transposed. >>
>>> Out[3]= Manipulate`Dump`eDynamicModule[Transpose
>>> [Manipulate`Dump`heldsetting[{{Hold[x]},{}}]],1,DynamicModuleValues:>
>>> {}]
>>>
>>> Compare that to ordinary module:
>>>
>>> In[4]:= Module[{x=Sequence[]},1]
>>> Out[4]= 1
>>>
>>> I discovered it a couple days after buying Mathematica 6, still
>>> excited about the new dynamic functionality. That was pretty
>>> disappointing;)
>>>
>>> Best,
>>> Norbert
>>>
>>> On Jan 19, 2:16 am, Istv=E1n <replicator...(a)gmail.com> wrote:
>>>>
>>>> Dear Group,
>>>>
>>>> I have some problem with a complex interface inside a DynamicModule.
>>>> This is a toy version of the program, which can fully reproduce the
>>>> malfunction:
>>>>
>>>> Panel(a)DynamicModule[
>>>> {x, y, assign, initialize},
>>>>
>>>> Grid[{
>>>> {"", "A", "B"},
>>>> {"w/ assign:", RadioButton[Dynamic[x, (x = #; assign) &], True]=
>>>
>>> ,
>>>>
>>>> RadioButton[Dynamic[x, (x = #; assign) &], False]},
>>>> {"w/o assign:", RadioButton[Dynamic@x, True],
>>>> RadioButton[Dynamic@x, False]},
>>>> {"value:", Dynamic@x}
>>>> }, Dividers -> {False, {False, True, True, True, False}},
>>>> Alignment -> {Left, {Center}}],
>>>>
>>>> Initialization :> (
>>>> assign := (y = x);(* further variables to update *)
>>>> initialize := (x = True; assign); (* initialization function =
>>>
>>> *)
>>>>
>>>> initialize;
>>>> )
>>>> ]
>>>>
>>>> Now for some reason, the radiobuttons do not function as intended (at
>>>> least as I want).
>>>> The following clicking orders do not work:
>>>>
>>>> [w/ + B] then [w/ + A]
>>>> [w/o + B] then [w/ + A]
>>>>
>>>> these work correctly:
>>>>
>>>> [w/ + B] then [w/o + A]
>>>> [w/o + B] then [w/o + A]
>>>>
>>>> I guess, that the problem is with the "initialize" (or the "assign")
>>>> function. Any idea?
>>>> Thanks in advance
>>>>
>>>> Istv=E1n
>>>
>>>
>>
>>
>> --
>> DrMajorBob(a)yahoo.com
>>
>


--
DrMajorBob(a)yahoo.com