MathGroup Archive 2007

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

Search the Archive

Re: Function[x...] and #& not equivalent

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74441] Re: Function[x...] and #& not equivalent
  • From: dh <dh at metrohm.ch>
  • Date: Wed, 21 Mar 2007 02:53:56 -0500 (EST)
  • References: <etof3e$i3d$1@smc.vnet.net>


Hi,

you are fooling yourself. The structure of:

Function[MkLength, MkLength[Eternity][

     Function[length, Function[list, If[EmptyQ[list], 0,

        1 + length[Rest[list]]]]]]][{}]

is: Function[MkLength,..][{}], the argument is {}. Therefore, you get 

{}[Eternity][...]. No further evaluation is possible. However, in:

#[Eternity]&[Function[length,Function[list,If[EmptyQ[list],0,1 + 

length[Rest[list]]]]]] [{}]

the argument is: Function[length,Function[list,If[EmptyQ[list],0,1 + 

length[Rest[list]]]]]. This evaluates to a new function that then takes 

the second argument {} and evaluates to 0.

Note that as long as your are not a real Mathematica crack, it is a good 

idea to make things simple.

Daniel



wooks wrote:

> 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

> 

> 




  • Prev by Date: Re: Integrate
  • Next by Date: Re: fastest way to add up a billion numbers
  • Previous by thread: Re: Function[x...] and #& not equivalent
  • Next by thread: compile speed