MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Selecting dynamically from a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84746] Re: Selecting dynamically from a list
  • From: John Jowett <John.M.Jowett at gmail.com>
  • Date: Fri, 11 Jan 2008 22:14:37 -0500 (EST)
  • References: <fm4hcd$6ts$1@smc.vnet.net> <fm4sl2$c25$1@smc.vnet.net>

Daniel,
      Thanks.  This almost solves the problem.  However a second call
to the function with the same symbol myVar will fail.   The missing
ingredient can be found in Jens' post if we change the order of the
arguments.

SetAttributes[choosein4, HoldFirst]

choosein4[myVar_Symbol, myl_List] :=
 Module[{mychoice1 = {}},
         Print[CheckboxBar[Dynamic@mychoice1, myl]];
         myVar := Setting[mychoice1]
       ]

Then

choosein4[myc, {a, b, c, d, e}]

can be evaluated repeatedly to assign different sublists to myc.   In
some cases though, it may still be convenient to use the method in my
first post.  That way you can change the selection without re-
evaluating the cell and use Setting[ ] in later cells which are
evaluated for further calculations using the "current" value of myc.

Of course, if the "further calculations" are small and quick enough,
they could simply be made Dynamic[  ] also.  In my application, they
are long and involve running an external program whose input depends
on myc.

John

On Jan 10, 11:39=A0am, dh <d... at metrohm.ch> wrote:
> 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 =A0get 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 = {}},
>
> =A0 =A0 Print[CheckboxBar[Dynamic@mychoice1, myl]];
>
> =A0 =A0 myVar:=Setting[mychoice1]]
>
> Note the delayed assignment that ensures the updating.
>
> hope this helps, Daniel
>
>
>
> 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 -



  • Prev by Date: Re: Selecting dynamically from a list
  • Next by Date: Re: changing the name of exported file without typing
  • Previous by thread: Re: Selecting dynamically from a list
  • Next by thread: question from amateur, why no demonstration for intersecting lines?