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

MathGroup Archive 2007

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

Search the Archive

Re: Function as an argument

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76730] Re: Function as an argument
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Sat, 26 May 2007 04:41:40 -0400 (EDT)
  • References: <f36ddj$71m$1@smc.vnet.net>

dXdYdZdu wrote:
> Hi, I have problem. I want to do something like this:
> 
> ss[x_] = 2 + x^3 ;
> MyFunction[expression_] := Module[{}, Return[expression[2]]]
> Calling MyFunction[ss] will produce 10 and this is working case.
> 
> but this is what I can not do:
> 
> MyFunction[2 + x^3]
> 
> Is there a way to make this to work as well?
> 
> 
> 
> 
> 
> 
Use a pure function:

MyFunction[2+#^3&]

BTW if you find this form a bit cryptic, try using 'Function' for a more 
explicit representation of the same thing.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: Function as an argument
  • Next by Date: Re: How to subtract two sets of data for a ListPlot
  • Previous by thread: Re: Function as an argument
  • Next by thread: Re: Function as an argument