MathGroup Archive 2005

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

Search the Archive

Re: UpValues for Blank[foo]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54267] Re: UpValues for Blank[foo]
  • From: Maxim <ab_def at prontomail.com>
  • Date: Mon, 14 Feb 2005 21:51:22 -0500 (EST)
  • References: <cud7du$2u7$1@smc.vnet.net> <200502110833.DAA09117@smc.vnet.net> <cukakr$lk1$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Sat, 12 Feb 2005 07:18:51 +0000 (UTC), Josef Karthauser  
<joe at tao.org.uk> wrote:

>
> I wonder what's I'm doing wrong.  I'm trying to change the upvalues of a
> function with respect to Blank[] so as to have it dynamically changed
> into something else, e.g.
>
>     := F /: Blank[F] := _?FQ
>
> where FQ[F] returns true, and false on anything else, but although
> installed it doesn't appear to work.
>
> To simplify the example I wondered whether I could define my own _F to
> behave like _Integer, i.e.
>
>     := F /: Blank[F] := Blank[Integer]
>
> which appears to be in place as a rule:
>
>     := ?? F
>     Global`F
>     _F := _Integer
>
> but doesn't work:
>
>     := _F // FullForm
>     Blank[F]
>
> I thought that maybe wrapping HoldPattern[] around the Blank[F] in the
> upvalue rule might have fixed it, but it doesn't.
>
> Is there some special handling for Blank[] within mathematica? Can I
> circumvent it somehow?
>
> Joe

It just shows that assignments to patterns have special meaning, and also  
that _F doesn't match _F (MatchQ[_F, _F] gives False) because _F has head  
Blank, not F. After the assignment _F = 0 you will have F[], F[1], F[1, 2]  
and so on evaluate to 0, but not _F itself. You can use Verbatim:

In[1]:=
Verbatim[_F] ^= _Integer;
MatchQ[1, _F]

Out[2]=
True

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: Re: rules and lists
  • Next by Date: Axes in ShowGraph
  • Previous by thread: UpValues for Blank[foo]
  • Next by thread: precision of numbers