Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Replacement in a held function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113320] Re: Replacement in a held function
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Sat, 23 Oct 2010 07:07:13 -0400 (EDT)
  • References: <i9r81q$hq2$1@smc.vnet.net>
  • Reply-to: nma at 12000.org

On 10/21/2010 10:39 PM, Istv=E1n Zachar wrote:
> Dear Group,
>
> How can the following toy example be modified to yield {1, 2, 3}
> instead of {t, t, t}? Suppose func, t and list are given parameters
> that cannot be changed, so I want to solve it with some kind of
> argument-replacement-inside-the-loop method. Thus I'm looking for a
> solution which only manipulates the internals of Do. If it is possible
> at all.
>
> In[104]:= list = {};
> func := AppendTo[list, t];
> Do[func /. {t ->  i}, {i, 3}];
> list
>
> Out[107]= {t, t, t}
>


one way:

glist = {};
func[t_] := AppendTo[glist, t];
Do[func[i], {i, 3}];
glist


Out[16]= {1, 2, 3}

--Nasser


  • Prev by Date: Re: Replacement in a held function
  • Next by Date: Re: From list to list of arguments
  • Previous by thread: Re: Replacement in a held function
  • Next by thread: Re: Replacement in a held function