Re: Question regarding procedures

*To*: mathgroup at smc.vnet.net*Subject*: [mg63428] Re: [mg63422] Question regarding procedures*From*: "David Park" <djmp at earthlink.net>*Date*: Sat, 31 Dec 2005 06:40:26 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

It is a little difficult to fathom exactly what you are trying to achieve here. On the other hand it is just the kind of thing I would fall into when I first started with Mathematica. In any case, it looks like you want a routine where you can supply different functions that will be evaluated. The method for doing that is to use pure functions. You can find these under Programming, Functional Programming in the Help Browser. So you might use something like the following... create[f_][x_] := f[x] create[#^2 &][3] 9 create[#^3 &][3] 27 Or you could write the fuller form of a Function create[Function[x, x^3]][3] 27 I don't think you would have to use a Module here. Also your func definition wouldn't need the {} parentheses, and x doesn't even appear on the rhs. And why Print the result when you could just get it as normal output? David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Dew 001 [mailto:dewdrops001 at gmail.com] To: mathgroup at smc.vnet.net Hi, I am relatively new to Mathematica and have the following question: I created a procedure where the value of fitn_ comes from the user ... create [fitn_]:=Module[{func }, func[{x_}]:=Evaluate[fitn]; Print[func[{3}]]; ] And called it with the following command: create[x^2] I was hoping to get a 9 .. and if create[x^3] is entered I hoped to get back 27. Any ideas? Thanks very much