Re: Selecting dynamically from a list
- To: mathgroup at smc.vnet.net
- Subject: [mg84745] Re: Selecting dynamically from a list
- From: John Jowett <John.M.Jowett at gmail.com>
- Date: Fri, 11 Jan 2008 22:14:06 -0500 (EST)
- References: <fm4hcd$6ts$1@smc.vnet.net> <fm4sfb$bv0$1@smc.vnet.net>
Jens, Thanks but this doesn't solve the problem (take a look at FullForm[mychoice] or InputForm[mychoice] and Length[mychoice] always evaluates to 1. I still need to use Setting[] ... John On Jan 10, 11:36=A0am, Jens-Peer Kuska <ku... at informatik.uni-leipzig.de> wrote: > Hi, > > SetAttributes[choosein, HoldFirst] > choosein[mychoice1_, myl_List] := > =A0 Module[{dynch}, dynch = mychoice1 = {}; > =A0 =A0CheckboxBar[mychoice1 = Dynamic@dynch, myl]] > > choosein[mychoice, {a, b, c, d, e, f}] > > and look what the variable mychoice include .. > > Regards > =A0 =A0Jens > > > > John Jowett wrote: > > Hello, > > =A0 =A0 =A0 =A0While writing this post, I found the solution myself. =A0= 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. =A0I 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. =A0After picking a couple I find > > that the variable mychoice0 has simply been assigned a value {a,c,e}, > > for example. =A0I can then go on and calculate other things with it, > > e.g., > > > Length[mychoice0] =A0 which returns 2. > > > So far, so good. =A0Then I try to build on that, by writing a function > > to pick from an arbitrary list. =A0After some trial and error, I came up= > > with > > > choosein[myl_List] := Module[{mychoice1 = {}}, > > =A0 Print[CheckboxBar[Dynamic@mychoice1, myl]]; > > =A0 Dynamic[mychoice1]] > > > and try it out with > > > myc = choosein[mylist] > > > Sure enough this displays an output corresponding to my choice from > > the check boxes. =A0 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. =A0This was puzzling until I > > discovered that > > > myc1 = Setting[myc] > > > will give the list I wanted. =A0However 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- Hide quoted text - > > - Show quoted text -