MathGroup Archive 2004

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

Search the Archive

Re: composing functions

  • To: mathgroup at
  • Subject: [mg45538] Re: composing functions
  • From: Paul Abbott <paul at>
  • Date: Tue, 13 Jan 2004 04:03:53 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <btthta$so5$>
  • Sender: owner-wri-mathgroup at

In article <btthta$so5$1 at>, Pedro L <pedrito6 at> 

> I  would  like  to find a way for composing a list of functions over a
> list of numbers.
> I  have  the  list  {{f,  g,  h},  {a,  b, c, d}}
> (f, g, h are functions and a, b, c, d are numbers)
> I would like to obtain h[g[f[a, b], c], d]

Here is one way:

  {fs, vars} = {{f, g, h}, {a, b, c, d}}; 

  i = 0; Fold[List,First[vars],Rest[vars]] /. List :> Reverse[fs][[++i]]

If you change Fold to have the HoldFirst attribute,

  SetAttributes[Fold, HoldFirst]

then you can write

 i = 0; Fold[fs[[++i]], First[vars], Rest[vars]]

I'm sure that someone will come up with a more elegant solution.


Paul Abbott                                   Phone: +61 8 9380 2734
School of Physics, M013                         Fax: +61 8 9380 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at 

  • Prev by Date: List arguments to functions
  • Next by Date: RE: composing functions
  • Previous by thread: Re: composing functions
  • Next by thread: RE: composing functions