Re: Bug, quirk or expected behavior of Slot[]?
- To: mathgroup at smc.vnet.net
- Subject: [mg101786] Re: [mg101759] Bug, quirk or expected behavior of Slot[]?
- From: "Elton Kurt TeKolste" <tekolste at fastmail.us>
- Date: Fri, 17 Jul 2009 05:02:47 -0400 (EDT)
- References: <200907161219.IAA02496@smc.vnet.net>
The third equation is symbolically different from the first two since, symbolically, y===y is true and y===0 is false. The local variable inside and the input parameter are different despite both being referenced by the symbol "y." All three functions are in fact the same as numeric functions: In[29]:= ex1 = Function[Module[{y = 0}, # === y]]; In[24]:= ex1 /@ Range[0, 3] Symbolic interpretation: input symbol y, set it to zero and check that it equals itself. Out[24]= {True, False, False, False} In[30]:= ex2 = Function[Module[{y = 0}, #1 === y]]; In[26]:= ex2 /@ Range[0, 3] Out[26]= {True, False, False, False} Symbolically the same as eq1. In[31]:= ex3 = Function[t, Module[{y = 0}, t === y]]; In[28]:= ex3 /@ Range[0, 3] Out[28]= {True, False, False, False} Symbolically: assign the symbolic parameter y to t, set a local parameter (named y but different) to zero and check y==0 Kurt On Thu, 16 Jul 2009 04:19 -0400, "Salvatore Mangano" <smangano at into-technology.com> wrote: > Someone on the "Linked In" Mathematica User group pointed this out to me: > > > In[26]:= Clear[y] > Function[Module[{y=0},#===y]][y] > Function[Module[{y=0},#1===y]][y] > Function[t,Module[{y=0},t===y]][y] > > Out[27]= True > Out[28]= True > Out[29]= False > > It leads me to believe # is more like a placeholder for macro-like > substitution than a formal parameter like t. > > Thoughts? >
- References:
- Bug, quirk or expected behavior of Slot[]?
- From: Salvatore Mangano <smangano@into-technology.com>
- Bug, quirk or expected behavior of Slot[]?