Re: Selecting dynamically from a list
- To: mathgroup at smc.vnet.net
- Subject: [mg84703] Re: Selecting dynamically from a list
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 10 Jan 2008 05:34:45 -0500 (EST)
- Organization: Uni Leipzig
- References: <fm4hcd$6ts$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi, SetAttributes[choosein, HoldFirst] choosein[mychoice1_, myl_List] := Module[{dynch}, dynch = mychoice1 = {}; CheckboxBar[mychoice1 = Dynamic@dynch, myl]] choosein[mychoice, {a, b, c, d, e, f}] and look what the variable mychoice include .. Regards Jens 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 > >