Re: Selecting dynamically from a list
- To: mathgroup at smc.vnet.net
- Subject: [mg84706] Re: Selecting dynamically from a list
- From: dh <dh at metrohm.ch>
- Date: Thu, 10 Jan 2008 05:36:17 -0500 (EST)
- References: <fm4hcd$6ts$1@smc.vnet.net>
Hi John using FullForm you can see what you get. E.g.: choosein[mylist]//FullForm will show you that the return value is Dynamic[..], not a value you can easily calulate with. However you have a real problem. If you get rid of the "Dynamic" you have a problem. Because, when you write var=choosein, the assignement is done once and not updated later. A possible solution would be to feed the variable to choosein, e.g.: choosein[myl_List,myVar_Symbol] := Module[{mychoice1 = {}}, Print[CheckboxBar[Dynamic@mychoice1, myl]]; myVar:=Setting[mychoice1]] Note the delayed assignment that ensures the updating. hope this helps, Daniel John Jowett wrote: > Hello, > While writing this post, I found the solution myself. At the > risk of making myself look a bit slow, let me communicate it anyway. > Conceivably it may help someone else who doesn't find the solution > obvious. > > I have an application where, in essence, I would like to visually pick > a few values out of a list to make a new list. I can do it at a basic > level with > > mylist = {a, b, c, d, e, f}; > > CheckboxBar[Dynamic[mychoice0], mylist] > > which displays a row of check boxes. After picking a couple I find > that the variable mychoice0 has simply been assigned a value {a,c,e}, > for example. I can then go on and calculate other things with it, > e.g., > > Length[mychoice0] which returns 2. > > So far, so good. Then I try to build on that, by writing a function > to pick from an arbitrary list. After some trial and error, I came up > with > > > choosein[myl_List] := Module[{mychoice1 = {}}, > Print[CheckboxBar[Dynamic@mychoice1, myl]]; > Dynamic[mychoice1]] > > and try it out with > > myc = choosein[mylist] > > Sure enough this displays an output corresponding to my choice from > the check boxes. However if I try to do anything else with the > variable myc, I quickly find out that it is not what it appears to be > and cannot be used in calculations. This was puzzling until I > discovered that > > myc1 = Setting[myc] > > will give the list I wanted. However it is NOT possible to > incorporate the call to Setting in the definition of the function > choosein. > > Can anyone improve on this approach ? > > John Jowett > >