Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*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 2002

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

Search the Archive

RE: passing functions as parameters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33999] RE: [mg33988] passing functions as parameters
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Fri, 26 Apr 2002 03:27:20 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----Original Message-----
> From: GoranG [mailto:icmc2MAKNUTIOVO at pop.tel.hr]
To: mathgroup at smc.vnet.net
> Sent: Thursday, April 25, 2002 9:00 AM
> To: mathgroup at smc.vnet.net
> Subject: [mg33999] [mg33988] passing functions as parameters
> 
> 
> 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],"Do
> ne","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.
> 
> All the best...
> 
> 

You nearly arrived...

In[2]:=
g[x_, y_, somefunction : (_Symbol | _Function)] := 
  If[somefunction[x] > somefunction[y], "Done", "Waiting"]


In[3]:= g[3, \[Pi], f]
Out[3]= "Waiting"

In[4]:= g[3, \[Pi], (1/# &)]
Out[4]= "Done"

--
Hartmut



  • Prev by Date: Re: a complex function appears in a real integration
  • Next by Date: Dynamic referencing AND hyperlinking for numbered equations
  • Previous by thread: RE: passing functions as parameters
  • Next by thread: Re: passing functions as parameters