RE: Re: Function as an argument of the function

• To: mathgroup at smc.vnet.net
• Subject: [mg34697] RE: [mg34677] Re: Function as an argument of the function
• From: "DrBob" <majort at cox-internet.com>
• Date: Sat, 1 Jun 2002 04:29:04 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```That code doesn't even execute:

OneArgFunctionQ[_] := False;
OneArgFunctionQ[Function[expr_]] :=
FreeQ[expr, Slot[n_ /; n > 1]] && FreeQ[expr, _SlotSequence];
OneArgFunctionQ[Function[vars_, expr_]] := Length[vars] == 1;

Function::flpar: Parameter specification vars_ in Function[vars_,expr_]
\
should be a symbol or a list of symbols.

If you decide to check DownValues, don't forget to check SubValues as
well.

However, built-in functions will defeat that method and perhaps ANY
method.

Bobby Treat

-----Original Message-----
From: Orestis Vantzos [mailto:atelesforos at hotmail.com]
To: mathgroup at smc.vnet.net
Subject: [mg34697] [mg34677] Re: Function as an argument of the function

maltomek at hotmail.com (Tomek) wrote in message
> Hi.
> I have to write a short function in Mathematica. But I have one
> problem with  it. One of arguments of my function have to be a
> function of one variable.
> How can I check if the argument of the function is a function of one
> variable (I wish there's FunctionQ)?

Well, if you limit your choice down to pure functions, you can use the
following code to check whether the pure function accepts a single
argument:

OneArgFunctionQ[_] := False;
OneArgFunctionQ[Function[expr_]] :=
FreeQ[expr, Slot[n_ /; n > 1]] && FreeQ[expr, _SlotSequence];
OneArgFunctionQ[Function[vars_, expr_]] := Length[vars] == 1;

Examples:
OneArgFunctionQ[#&] --> True
OneArgFunctionQ[#+#2&] --> False
OneArgFunctionQ[Function[{x},x^2]] --> True
OneArgFunctionQ[Function[{x,y},x+y]] --> False

If you want to check symbols like Sin, Cos, etc. things get ugly
really fast.
You could theoreticaly check the DownValues of the symbol, but I
wouldn't bother unless it was absolutely imperative.
Orestis

```

• Prev by Date: Re: Increased Precision in Plot?
• Next by Date: RE: Re: Function as an argument of the function
• Previous by thread: RE: Re: Function as an argument of the function
• Next by thread: RE: Re: Function as an argument of the function