RE: bug with definitions?
- To: mathgroup at smc.vnet.net
- Subject: [mg40401] RE: [mg40373] bug with definitions?
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Fri, 4 Apr 2003 01:21:39 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: scundal at yahoo.com [mailto:scundal at yahoo.com] To: mathgroup at smc.vnet.net >Sent: Thursday, April 03, 2003 8:43 AM >To: mathgroup at smc.vnet.net >Subject: [mg40401] [mg40373] bug with definitions? > > >Why does the following code cause and exception? I thought that the >left hand side of := was not evaluated. > >Clear[a, z]; >z[x_Integer] := 2; >z[x_] := Throw[11]; >a[i_, iUp_?z] := 3; >a[i_Integer, iUp_?z] := 5; > >Cheers, >Hein > Hein, well, your assumption simply is not correct. If several definitios are made to the same symbol, mathematica tries to bring them into order such that there are no definitions shadowed. For this left-hand sides may be partially evaluated. See: In[2]:= f::"killroy" = "was here!"; In[3]:= z[_] := Message[f::"killroy"] In[4]:= f[i_, j_?z] := 1 In[5]:= f[i_] := 2 In[6]:= f[i_, j_] := 3 >From In[6]:= f::"killroy": "was here!" In[7]:= f[i_, Sqrt[4]] := 4 >From In[7]:= f::"killroy": "was here!" In[8]:= f[i_, j_, k_] := 5 In[9]:= ?f Global`f f[i_, j_?z] := 1 f[i_] := 2 f[i_, 2] := 4 f[i_, j_] := 3 f[i_, j_, k_] := 5 Above, for line 5, there are no potential conflicts, nothing happens. for line 6, there is a potential conflict of the new definition with that one of line 4, such z is tried and the message issued. for line 7, dito, also observe how Sqrt[4] is evaluated to 2 for the resulting definition. It will be placed before definition of line 6, but not before the first definition. for line 8, again there is not potential conflict. If you define instead at line 2: z[_Integer] := ... then you'll only get the message at line 7, if you define z[Verbatim[j_]] := ... then you'll get only the message at line 6 -- Hartmut Wolf