From: Carlos César de Araújo on
David Bailey wrote:

>>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!

Well, this is not a valid argument: I´m not using an isolated Except in a
transformation rule. According to the documentation, "Except[c] is a
pattern object which represents any expression except one that matches c."
In particular, given a pattern patt, we should have, for all expressions
expr,

MatchQ[expr, Except[patt]] iff !MatchQ[expr,patt]

But there are (many!) situations where a named patt is useful in
!MatchQ[expr,patt]. Example: my definition of FunctionQ. That definition
works with a named patt in MatchQ, so it should work with Except instead.

A "Possible Issues" in the documentation would help.

--
Atenciosamente,

Carlos César de Araújo
Gregos & Troianos Educacional
www.gregosetroianos.mat.br
Belo Horizonte, MG, Brasil
(31) 3283-1122

From: Bob Hanlon on
There are multiple ways to get the intended result:

DeleteCases[{-0.5, 1, -3, 2/5, I}, _Integer]

{-0.5, 2/5, I}

Select[{-0.5, 1, -3, 2/5, I}, ! IntegerQ[#] &]

{-0.5, 2/5, I}

Cases[{-0.5, 1, -3, 2/5, I}, _?(! IntegerQ[#] &)]

{-0.5, 2/5, I}


Bob Hanlon

---- David Bailey <dave(a)removedbailey.co.uk> wrote:

=============
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



From: David Bailey on
On 20/06/10 08:46, Carlos C=E9sar de Ara=FAjo wrote:
> David Bailey wrote:
>
>>> 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!
>
> Well, this is not a valid argument: I'm not using an isolated Except in a
> transformation rule. According to the documentation, "Except[c] is a
> pattern object which represents any expression except one that matches c."
> In particular, given a pattern patt, we should have, for all expressions
> expr,
>
> MatchQ[expr, Except[patt]] iff !MatchQ[expr,patt]
>
> But there are (many!) situations where a named patt is useful in
> !MatchQ[expr,patt]. Example: my definition of FunctionQ. That definition
> works with a named patt in MatchQ, so it should work with Except instead.
>
The name belongs to the scope of the rule, so for example:

In[2]:= MatchQ[7, x_Integer]; x

Out[2]= x

I do admit, the rule is a bit strange because it forbids constructions
like:

Except[x_Integer /; testQ[x]]

Anyway, the restriction was obviously put in deliberately, so it is
unlikely to become classed as a bug.

David Bailey

http://www.dbaileyconsultancy.co.uk

 | 
Pages: 1
Prev: Setting PageSize and PaperSize
Next: Book?