Re: Modify a list of pure functions
- To: mathgroup at smc.vnet.net
- Subject: [mg70827] Re: [mg70812] Modify a list of pure functions
- From: "Chris Chiasson" <chris at chiasson.name>
- Date: Sat, 28 Oct 2006 23:38:00 -0400 (EDT)
- References: <200610280921.FAA16098@smc.vnet.net>
You are running into problems with the HoldAll Attribute of Function. ReplaceAll can replace things inside held expressions, but I would really recommend using non-pure "functions" instead of trying to be precise with ReplaceAll. On 10/28/06, . <ggroup at sarj.ca> wrote: > Hi all, > > I have a problem where I need to build up a list of pure functions that > have been modified from a base pure function. I'm not having much luck > in getting it to work correctly, and was wondering if anyone had some > good ideas. A toy version of the problem is: > > f = Sin[#]& > listF = Table[(i f[##])&, {i, 5}] > > What I'd hope to get is listF containing: > {Sin[##]&, (2 Sin[##])&, (3 Sin[##])&, (4 Sin[##])&, (5 Sin[##])&} > > But instead, I get something where neither i nor f have been evaluated. > As I say, this is a toy example. One thing that does partially work > for the toy case, but does not seem to work for more complicated > situations is to use ReplaceAll: > > listF2 = Table[{j f[##])& /. j->i, {i,5}] > > This does give: > {1 f[##1] &, 2 f[##1] &, 3 f[##1]&, 4 f[##1] &, 5 f[##1] &} > > However, all that has been done is the index has been inserted; no > significant evaluation seems to have occurred. So this method doesn't > work in more complicated situations. For example, suppose insted of > using the index i directly, it actually referred to a list: > > coeffs = Reverse[ Range[5] ]; > listF3 = Table[ (coeffs[[j]] f[##]) & /. j->i, {i, 5}] > > This just gives: > {coeffs[[1]]*f[##1] & , coeffs[[2]]*f[##1] & , coeffs[[3]]*f[##1] & , > coeffs[[4]]*f[##1] & , coeffs[[5]]*f[##1] & } > > Which is no good if coeffs is a temporary variable. > > Any suggestions would be most appreciated. Thanks! > > -- http://chris.chiasson.name/
- References:
- Modify a list of pure functions
- From: "." <ggroup@sarj.ca>
- Modify a list of pure functions