RE: Not accepting function as parameter

*To*: mathgroup at smc.vnet.net*Subject*: [mg71730] RE: [mg71681] Not accepting function as parameter*From*: "Mark Harder" <harderm at onid.orst.edu>*Date*: Tue, 28 Nov 2006 06:03:34 -0500 (EST)

When I inserted Print[width] before f[width] in the definition of happy and ran the program, it wouldn't even execute the Print[]. I imagine this was because happy couldn't match Sin with _Function. So I removed the Function requirement and for simplicity also the Module structure. Then I created a function out of f and named it fnc. The following works. Clear[happy] happy[ f_, a_Integer, b_Integer] := (fnc = f[#] &; width = N[(b - a)/1000 ]; ans = fnc[width] ) happy[Sin, 1, 21] 0.0199987 -Mark Harder > -----Original Message----- > From: wooks [mailto:wookiz at hotmail.com] > Sent: Sunday, November 26, 2006 12:49 AM > To: mathgroup at smc.vnet.net > Subject: [mg71681] Not accepting function as parameter > > This is a piece of experimental code. The function happy does not > evaluate whenever I pass f as a parameter as in the example below. > > Clear[happy] > happy[ f_Function, a_Integer, b_Integer] := Module[{width = (b - > a)/1000}, > f[width]]; > > happy[ Sin, 1, 21] > > I'd be grateful for help. >