Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re:Applying List of Functions To List Of Arguments

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30214] Re:[mg30181] Applying List of Functions To List Of Arguments
  • From: Ranko Bojanic <bojanic at math.ohio-state.edu>
  • Date: Thu, 2 Aug 2001 03:16:08 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated Wed,1 Aug 2001 02:19:46-0400 (EDT),rml27 at cornell.edu 
(Ronnen Levinson) writes:

> To:mathgroup at smc.vnet.net
> Subject:[mg30181] Applying List of Functions To List Of Arguments
> Hi.What function or operator will let me apply a list of functions to a
> list of arguments?That is,I'd like to apply {f1,f2,f3} to {a,b,c} to
> get {f1[a],f2[b],f3[c]}.
> Yours truly, Ronnen.

The following function does that: 
        ClearAll[w,f,g,h,x,y,z]
        
        w[f_,x_]:=f[x]
        SetAttributes[w,Listable]
        
        w[{f,g,h},{x,y,z}]
        {f[x],g[y],h[z]}

It is easy to explain  why this works. 
Listable functions of 2 variables when applied to two lists of the same
length are automatically threaded over these lists:
w[{f,g,h},{x,y,z}] ={w[f,x],w[g ,y], w[h,z]}
                            = {f[x], g[y], h[z]}
Without Listability,  we have to use Thread, as it was shown recently
by Alan Hayes:

p[f_,x_]:=f[x]
Thread[Unevaluated[p[{f,g,h},{x,y,z}]]]
{f[x], g[y], h[z]}

Ranko        


  • Prev by Date: Re: Applying List of Functions To List Of Arguments
  • Next by Date: RE: Lost Line Directives in 3D Graphics
  • Previous by thread: Re: Applying List of Functions To List Of Arguments
  • Next by thread: How Do I Solve This System of 6 Inequalities?