MathGroup Archive 2006

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

Search the Archive

RE: Not accepting function as parameter

	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.

happy[ f_, a_Integer, b_Integer] :=
  (fnc = f[#] &;
    width = N[(b - a)/1000 ];
    ans = fnc[width] )

happy[Sin, 1, 21]

-Mark Harder

> -----Original Message-----
> From: wooks [mailto:wookiz at]
> Sent: Sunday, November 26, 2006 12:49 AM
> To: mathgroup at
> 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.

  • Prev by Date: Re: Integration (change of variable)
  • Next by Date: Re: Re: Converting an expression to a list of terms?
  • Previous by thread: Re: Not accepting function as parameter
  • Next by thread: Re: Not accepting function as parameter