Re: Conditional evaluations of functions
- To: mathgroup at smc.vnet.net
- Subject: [mg96506] Re: Conditional evaluations of functions
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Sun, 15 Feb 2009 03:20:06 -0500 (EST)
- References: <gn5udh$gsv$1@smc.vnet.net>
Hi,
your function does not work because you use the wrong syntax,
you mean
g[x_?(VectorQ[#, NumericQ] &)] := Total[x]
Regards
Jens
Asim wrote:
> Hi
>
> I am not sure why the function g does not work, but the function f
> works as expected on Mathematica 7.0 on Windows XP. I want to get the
> sum of a vector only if the argument supplied is a numeric vector.
>
> In[1]:= g[x_?VectorQ[ x, NumericQ]] := Total[x]
>
> In[2]:= g[{a, b , c}]
>
> Out[2]= g[{a, b, c}]
>
> In[3]:= g[{1, 2, 3}]
>
> Out[3]= g[{1, 2, 3}]
>
> In[4]:= f[x_ /; VectorQ[x, NumericQ]] := Total[x]
>
> In[5]:= f[{a, b, c}]
>
> Out[5]= f[{a, b, c}]
>
> In[6]:= f[{1, 2, 3}]
>
> Out[6]= 6
>
> I also found different behavior for the function g, in Mathematica
> 6.0, which also was not what I wanted.
>
> Thanks
>
> Asim
>