MathGroup Archive 2002

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

Search the Archive

Re: passing functions as parameters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34000] Re: [mg33988] passing functions as parameters
  • From: BobHanlon at aol.com
  • Date: Fri, 26 Apr 2002 03:27:21 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 4/25/02 4:24:11 AM, icmc2MAKNUTIOVO at pop.tel.hr writes:

>How would one pass one function to another?
>
>I need to be able to define functions in the following fashion:
>
>f[x_]:=x^3-x+1
>
>g[x_,y_,somefunction?]:=If[somefunction[x]>somefunction[y],"Done","Waiting")
>
>to be able to later on evaluate
>
>g[2.,3., f?]
>
>I have tried couple of paths with no success and would really like to
>avoid using global function in function g.

f[x_]:=x^3-x+1;

g[x_,y_,func_]:=If[func[x]>func[y],"Done","Waiting"];

{g[2,3,f], g[3,2,f]}

{"Waiting", "Done"}


or with a pure function


{g[0,Pi/2, Sin[#]&], g[0,Pi/2, Cos[#]&]}

{"Waiting", "Done"}


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: passing functions as parameters
  • Next by Date: 3D contour through a point
  • Previous by thread: Re: passing functions as parameters
  • Next by thread: RE: passing functions as parameters