Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Named patterns forbidden in Except?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110506] Re: Named patterns forbidden in Except?
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Tue, 22 Jun 2010 06:59:17 -0400 (EDT)
  • References: <hvkgvo$qce$1@smc.vnet.net>

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


  • Prev by Date: Re: Book?
  • Next by Date: Re: Help me : Solve a simple PDE in Mathematica
  • Previous by thread: Re: Named patterns forbidden in Except?
  • Next by thread: Compiled function not working