       Re: Re: Variable amount of Buttons in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg92882] Re: [mg92851] Re: Variable amount of Buttons in Mathematica
• From: Fred Simons <f.h.simons at tue.nl>
• Date: Thu, 16 Oct 2008 05:07:27 -0400 (EDT)
• References: <gcscrf\$8l3\$1@smc.vnet.net> <gcv77d\$ds9\$1@smc.vnet.net> <200810150937.FAA11741@smc.vnet.net>

```The problem discussed in this thread is caused by the HoldRest attribute
of Button, and therefore is essentially the same as

In:= Table[Hold[n], {n,1,5}]
Out= {Hold[n],Hold[n],Hold[n],Hold[n],Hold[n]}

returning a list of 5 elements Hold[n].

Since Hold does not evaluate its argument, we have to *substitute*
values for n in Hold[n] rather than assigning values to n.

Here is one solution (you might replace Hold with the Button you are
interested in):

In:= Table[Hold[n] /. n->i, {i,1,5}]
Out= {Hold,Hold,Hold,Hold,Hold}

The With-solutions are based on the fact that in the evaluation of
With[{n=something}, argument] the first step is *substitution* of the
value something for n in the expression argument; despite the syntax no
assignments are involved.

In:= Table[With[{n=n},Hold[n]], {n,1,5}]
Out= {Hold,Hold,Hold,Hold,Hold}

As can be seen from the syntaxcolouring, the second n in n=n is the
counter of the Table command, while the first n is the vehicle that
takes care of the substitution in the second argument of With.

Still another construction, which I have not seen mentioned, and easier
to understand than the With construction, is based on the fact that
mapping also uses substitution:

In:= Hold[#]& /@ Range
Out= {Hold,Hold,Hold,Hold,Hold}

A variant of this is

In:= Array[Hold[#]&, 5]
Out= {Hold,Hold,Hold,Hold,Hold}

Kind regards,

Fred Simons
Eindhoven University of Technology

```

• Prev by Date: Re: Newbie question: equations with sums.
• Next by Date: Re: Newbie question: equations with sums.
• Previous by thread: Re: Variable amount of Buttons in Mathematica
• Next by thread: Re: Variable amount of Buttons in Mathematica