Function[x...] and #& not equivalent
- To: mathgroup at smc.vnet.net
- Subject: [mg74420] Function[x...] and #& not equivalent
- From: "wooks" <wookiz at hotmail.com>
- Date: Tue, 20 Mar 2007 05:57:28 -0500 (EST)
In[19]:= Clear[Eternity,x]; Eternity[x_]:=Eternity[x]; In[21]:= Clear[EmptyQ]; EmptyQ[{}]:=True; EmptyQ[x_List]:=False; EmptyQ[x_]:=Print["Argument to EmptyQ must be a list."]; This below works for the empty list it gives 0. In[25]:= Clear[length,list] Function[length, Function[list,If[EmptyQ[list], 0, 1 + length[Rest[list]]]]][ Eternity][{}] Out[26]= 0 What I am trying to do here is pass the function above as the definition of the parameter MkLength and then run the exactly the same thing by MkLength[Eternity]. It doesn't work. In[27]:= Function[MkLength,MkLength[Eternity][Function[length, Function[list,If[EmptyQ[list],0,1 + length[Rest[list]]]]]]][{}] Out[27]= {}[Eternity][ Function[length,Function[list,If[EmptyQ[list], 0,1+length[Rest[list]]]]]] But look what happens when I use the function abbreviation instead of Function[MkLength........ In[29]:= #[Eternity]&[Function[length, Function[list,If[EmptyQ[list],0,1 + length[Rest[list]]]]]] [{}] Out[29]= 0