From: cca on
Hi,

Consider this:

In[1]:= Cases[{-0.5, 1, -3, 2/5, I}, Except[x_Integer]]

During evaluation of In[1]:= Except::named: Named pattern variables are not
allowed in the first argument of Except[x_Integer]. >>

Out[1]= {}

Why are named patterns not allowed in Except?

Recently, during a course of mine (on Mathematica), I needed to illustrate
the concept of function as a set of ordered pairs. I had the following
definiton(inter alia):

FunctionQ[f_] := MatchQ[f, {{_, _} ...}] &&
! MatchQ[f, {___, {x_, _}, ___, {x_, _}, ___}]

Then it occurred to me to use Except with two arguments just to give it a
chance to shine in the course:

(*doesn=B4t work!*)
FunctionQ[f_] :=
MatchQ[f, Except[{___, {x_, _}, ___, {x_, _}, ___}, {{_, _} ...}]]

Wouldn't this be simpler and natural? I would much appreciate any
explanation...

Atenciosamente,

Carlos C=E9sar de Ara=FAjo
Gregos & Troianos Educacional
www.gregosetroianos.mat.br
Belo Horizonte, MG, Brasil
(31) 3283-1122

From: David Bailey on
On 18/06/10 06:25, cca(a)gregosetroianos.mat.br wrote:
> Hi,
>
> Consider this:
>
> In[1]:= Cases[{-0.5, 1, -3, 2/5, I}, Except[x_Integer]]
>
> During evaluation of In[1]:= Except::named: Named pattern variables are not
> allowed in the first argument of Except[x_Integer].>>
>
> Out[1]= {}
>
> Why are named patterns not allowed in Except?
>


I guess the point is that you could never use the name - because in your
example, if x took a value, Except would fail to match by definition!

David Bailey

http://www.dbaileyconsultancy.co.uk