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: [mg74448] Re: Function[x...] and #& not equivalent
  • From: "Szabolcs" <szhorvat at gmail.com>
  • Date: Wed, 21 Mar 2007 02:57:43 -0500 (EST)
  • References: <etof3e$i3d$1@smc.vnet.net>

wooks =EDrta:
> 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

The abbreviated notation is equivalent with the first version only if
you put the ampersand at the end.

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

What you have written there can be expressed with the Function
notation as follows:

Function[MkLength, MkLength[Eternity]] [Function[length,
         Function[list,If[EmptyQ[list],0,1 + length[Rest[list]]]]]]
[{}]



  • Prev by Date: Re: how to find complete integral of pde
  • Next by Date: Re: Re: Membrane
  • Previous by thread: Re: Function[x...] and #& not equivalent
  • Next by thread: Re: Function[x...] and #& not equivalent