Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Initialization problem in a DynamicModule

42 views
Skip to first unread message

István

unread,
Jan 19, 2010, 5:16:25 AM1/19/10
to
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@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

Patrick Scheibe

unread,
Jan 20, 2010, 6:45:57 AM1/20/10
to
Hi,

it matters that your assign and initialize functions have DownValues.

Panel@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

David Park

unread,
Jan 20, 2010, 6:46:07 AM1/20/10
to
Does this work for you:

Panel@DynamicModule[
{x = True, y, assign},

Attributes[assign] = HoldAll;
assign[x_, y_] := y = x;
assign[x, y];



Grid[{{"", "A", "B"},
{"w/ assign:",

RadioButton[Dynamic[x, (x = #; assign[x, y]) &], True],
RadioButton[Dynamic[x, (x = #; assign[x, y]) &], 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}}]]


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/

Ariel Sepulveda

unread,
Jan 20, 2010, 6:48:31 AM1/20/10
to
This seems to work fine:

Panel@DynamicModule[{x, y, assign, initialize},

initialize[];
assign[];


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;);(*initialization function*))]

I assume that the problem is that you should initialize at the beginning of
the code and not inside the initialization script. Recall that
DynamicModule remembers all local variables so, once defined you don't need
to have them reinitialized every time the Initialization is evaluated (i.e.
everytime the DynamicModule is evaluated the first time in a Mathematica
session). Besides, if you try to initialize inside Initialization, you
would be asking the DynamicModule to redefine local variables in each new
session, and that is not what is expected from DynamicModule but local
variables should keep latest session values.

Hope this helps.

Ariel Sepulveda

Norbert P.

unread,
Jan 20, 2010, 6:50:22 AM1/20/10
to
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@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...@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@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 =

István

unread,
Jan 20, 2010, 6:51:39 AM1/20/10
to
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?

DrMajorBob

unread,
Jan 21, 2010, 4:50:51 AM1/21/10
to
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?

Bobby

On Wed, 20 Jan 2010 05:46:01 -0600, Patrick Scheibe
<psch...@trm.uni-leipzig.de> wrote:

> Hi,
>
> it matters that your assign and initialize functions have DownValues.
>

> Panel@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án 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@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
>>
>
>


--
DrMaj...@yahoo.com

DrMajorBob

unread,
Jan 21, 2010, 4:51:02 AM1/21/10
to
> 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. <berta...@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@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...@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@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
>
>


--
DrMaj...@yahoo.com

Patrick Scheibe

unread,
Jan 21, 2010, 4:52:09 AM1/21/10
to
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 =


<psch...@trm.uni-leipzig.de
> > wrote:
>
>> Hi,
>>
>> it matters that your assign and initialize functions have DownValues.
>>

>> Panel@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@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 =

Norbert Pozar

unread,
Jan 21, 2010, 4:52:30 AM1/21/10
to
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 <btr...@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. <berta...@gmail.com> wro=

>>> 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@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
>>
>>
>
>

> --
> DrMaj...@yahoo.com
>

DrMajorBob

unread,
Jan 21, 2010, 4:54:22 AM1/21/10
to
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 <berta...@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@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
>>>
>>>
>>
>>

>> --
>> DrMaj...@yahoo.com
>>
>


--
DrMaj...@yahoo.com

Ariel Sepulveda

unread,
Jan 21, 2010, 4:57:08 AM1/21/10
to
Itsvan:

Assigning values inside Initializaiton causes the DynamicModule to change
last session values with initialization values. My opinion is that this is
not wrong but is not what is intended/expected from DynamicModule. You can
try creating both cases and then comparing behavior after quitting Kernel.

Ariel

On Wed, Jan 20, 2010 at 7:51 AM, Istv=E1n <replic...@gmail.com> wrote:

> 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++]))
>
>


--
Ariel Sepulveda, Ph.D.
__________________________
President, Pronto Analytics Inc.
Tel. 787.354.6947
ariel.s...@prontoanalytics.com
http://www.prontoanalytics.com


0 new messages