MathGroup Archive 1999

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

Search the Archive

Re: Why () around Function in pattern?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16439] Re: Why () around Function in pattern?
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 13 Mar 1999 02:21:48 -0500
  • References: <7c59uk$7of@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Kevin Jaffe wrote in message <7c59uk$7of at smc.vnet.net>...
>Why does this "work"
>
>In[172]:= q[{x_Integer, y_Integer} ?
>            (Function[v, v.v > 4])] := qp[x + y]
>In[173]:= q[{3, 4}]
>Out[173]= qp[7]
>
>while this doesn't?:
>
>In[174]:= qq[{x_Integer, y_Integer} ?
>            Function[v, v.v > 4]] := qp[x + y]
>In[175]:= qq[{3, 4}]
>Out[175]= qq[{3, 4}]
>
>I.e., why are ()'s necessary around the pure function
>in the arguments pattern?

Kevin:


The FullForms are

HoldForm[FullForm[ q[{x_Integer, y_Integer} ?
(Function[v, v.v > 4])]]]

qq[PatternTest[List[Pattern[x,Blank[Integer]],Pattern[y,Blank[Integer]]],
    Function[v,Greater[Dot[v,v],4]]]]

and

HoldForm[FullForm[ q[{x_Integer, y_Integer} ?
Function[v, v.v > 4]]]]

qq[PatternTest[List[Pattern[x,Blank[Integer]],Pattern[y,Blank[Integer]]],
      Function][v,Greater[Dot[v,v],4]]]

Without the parentheses PatternTest grabs just Function, not all of
Function[...]

We get

qqq[{x_Integer, y_Integer} ?
(True&)[v, v.v > 4]] := qp[x + y]

qqq[{3,4}[v, v.v > 4]]

qp[7]

The precedence of operators is listed in the Mathematica Book A 2.7

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565







  • Prev by Date: Re: planar polygon plot
  • Next by Date: Re: Urgent aid needed
  • Previous by thread: Why () around Function in pattern?
  • Next by thread: Re: Why () around Function in pattern?