MathGroup Archive 2006

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

Search the Archive

Re: Modify a list of pure functions


. 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!
>  
>
Try using Evaluate:

listF3 = Table[ Evaluate[coeffs[[i]] f[##]] &, {i,5}]

Carl Woll
Wolfram Research


  • Prev by Date: Re: How to change file names?
  • Next by Date: RE: Modify a list of pure functions
  • Previous by thread: Modify a list of pure functions
  • Next by thread: Re: Modify a list of pure functions