From: asdf qwerty on
Why does this work:

DynamicModule[{foo}, PopupMenu[Dynamic[foo], {bar, baz}]]

but this doesn't:

DynamicModule[{foo, bar, baz}, PopupMenu[Dynamic[foo], {bar, baz}]]

?

In the second example, the PopupMenu display always looks blank. Are
the two occurrences of bar and baz in different scopes or something?

I ran into this because I'm trying to avoid possible symbol clashes
for my PopupMenu values, for the reason described near the beginning
of the "Advanced Dynamic Functionality" tutorial ("a different kernel
session may coincidentally share the same localized variable names").
I'd like to use symbols for the PopupMenu values rather than say,
integers, because it makes the code easier to read.

From: Sjoerd C. de Vries on
If you want to have labels in the pop-up for better readability why
don't you use the

PopupMenu[x,{Subscript[val, 1]->Subscript[lbl, 1],Subscript[val, 2]-
>Subscript[lbl, 2],\[Ellipsis]}]

syntax version of PopupMenu?

Cheers -- Sjoerd

On Feb 11, 1:52 pm, asdf qwerty <bradc355...(a)yahoo.com> wrote:
> Why does this work:
>
> DynamicModule[{foo}, PopupMenu[Dynamic[foo], {bar, baz}]]
>
> but this doesn't:
>
> DynamicModule[{foo, bar, baz}, PopupMenu[Dynamic[foo], {bar, baz}]]
>
> ?
>
> In the second example, the PopupMenu display always looks blank. Are
> the two occurrences of bar and baz in different scopes or something?
>
> I ran into this because I'm trying to avoid possible symbol clashes
> for my PopupMenu values, for the reason described near the beginning
> of the "Advanced Dynamic Functionality" tutorial ("a different kernel
> session may coincidentally share the same localized variable names").
> I'd like to use symbols for the PopupMenu values rather than say,
> integers, because it makes the code easier to read.


From: asdf qwerty on
I actually am using labels in my code; I was just trying to keep the
example simple. The code readability problem isn't here in the
PopupMenu, it's elsewhere, where I process the value of the variable
by switching on its value. I don't want to have to have a bunch of
cases labeled by cryptic integers. I'd like to do something like this
(which doesn't work):

DynamicModule[
{x, even, odd},
{
PopupMenu[Dynamic[x], {
even -> "even",
odd -> "odd"
}],
(* ...intervening code... *)
Dynamic[Switch[x,
even, 2 n,
odd, 3 n + 1
]]
}
]

In the meantime, I noticed that if I assign integer values to the
symbols, then everything works, and it seems to still scope my symbols
safely. I.e., I can't break the running Dynamics by assigning new
values to the mangled names (which contain dollar signs) like I can if
I just use a regular Module. The working code looks like this:

DynamicModule[
{x, even = 0, odd = 1},
{
PopupMenu[Dynamic[x], {
even -> "even",
odd -> "odd"
}],
(* ...intervening code... *)
Dynamic[Switch[x,
even, 2 n,
odd, 3 n + 1
]]
}
]

I still don't really understand why this change makes it work when it
didn't work before though...

On Feb 12, 1:42 am, "Sjoerd C. de Vries" <sjoerd.c.devr...(a)gmail.com>
wrote:
> If you want to have labels in the pop-up for better readability why
> don't you use the
>
> PopupMenu[x,{Subscript[val, 1]->Subscript[lbl, 1],Subscript[val, 2]-
>
> >Subscript[lbl, 2],\[Ellipsis]}]
>
> syntax version of PopupMenu?
>
> Cheers -- Sjoerd
>
> On Feb 11, 1:52 pm, asdf qwerty <bradc355...(a)yahoo.com> wrote:
>
> > Why does this work:
>
> > DynamicModule[{foo}, PopupMenu[Dynamic[foo], {bar, baz}]]
>
> > but this doesn't:
>
> > DynamicModule[{foo, bar, baz}, PopupMenu[Dynamic[foo], {bar, baz}]]
>
> > ?
>
> > In the second example, the PopupMenu display always looks blank. Are
> > the two occurrences of bar and baz in different scopes or something?
>
> > I ran into this because I'm trying to avoid possible symbol clashes
> > for my PopupMenu values, for the reason described near the beginning
> > of the "Advanced Dynamic Functionality" tutorial ("a different kernel
> > session may coincidentally share the same localized variable names").
> > I'd like to use symbols for the PopupMenu values rather than say,
> > integers, because it makes the code easier to read.