MathGroup Archive 2006

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

Search the Archive

Re: Not accepting function as parameter

  • To: mathgroup at
  • Subject: [mg71774] Re: Not accepting function as parameter
  • From: "Andrew Moylan" <andrew.j.moylan at>
  • Date: Wed, 29 Nov 2006 02:56:03 -0500 (EST)
  • References: <ekbmj4$f87$>

As other posters have pointed out, not all (or even most) functions
have head Function. Some have head Symbol. Really, in Mathematica,
anything might be a function. In this example, the head is
Derivative[1]: happy[Derivative[1][g], 1, 21]. In general, I think you
just have to introduce your function happy as happy[f_, a_Integer,
b_Integer], with no restriction on the first argument.

To get really wild: one could conceive of a pattern that tests (by
inspecting DownValues[f], SubValues, etc.) whether the argument f will
behave as a suitable function. But such a test would also have to be
too restrictive, since in not possible (even in principle---Godel's
theorem and all that), given the definition of a function, to determine
whether it's going to always return e.g. a number.

On Nov 26, 8:25 pm, "wooks" <woo... at> wrote:
> 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: Strange empty set of solutions
  • Next by Date: Re: sum of integrals over patial intervals != integral
  • Previous by thread: Re: Not accepting function as parameter
  • Next by thread: SetPrecision vs N