Re: Whitespace weirdness.
- To: mathgroup at smc.vnet.net
- Subject: [mg74382] Re: Whitespace weirdness.
- From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
- Date: Mon, 19 Mar 2007 21:59:42 -0500 (EST)
- References: <BAY135-F10BABD11C097B92A5D3A88C0760@phx.gbl>
On 3/19/07, wooks . <wookiz at hotmail.com> wrote:
>
> >From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
> >To: wooks <wookiz at hotmail.com>, mathgroup at smc.vnet.net
> >Subject: Re: Whitespace weirdness.
> >Date: Mon, 19 Mar 2007 11:59:16 +0100
> >
> >wooks wrote:
> >>Clear[Eternity,x];
> >>Eternity[x_]:=Eternity[x];
> >
> >Totally buggy function definition for his definition leads to infinite
> >recursion.
> >
>
> It's intentional. It's building up to the halting problem.
OK, I see. I stand corrected.
> >>Clear[EmptyQ];
> >>EmptyQ[{}] := True;
> >>EmptyQ[x_List] := False;
> >>EmptyQ[x_] := Print["Argument to EmptyQ must be a list."];
> >>
> >>Clear[length,list,f,g]
> >>Function[f,
> >> Function[list,If[EmptyQ[list],0,
> >> 1+f[Rest[list]]]]]
> >>
> >>[Function[g,
> > >
> >>Function[list,If[EmptyQ[list], 0,
> >> 1 +
> >>g[Rest[list]]]]][Eternity]]
> >>
> >>Clear[length,list,f,g]
> >>Function[f,
> >> Function[list,If[EmptyQ[list],0,
> >> 1+f[Rest[list]]]]]
> >>[Function[g,Function[list,If[EmptyQ[list], 0,
> >==^
> >Funny extra open square bracket.
> >
>
> It's not extra
Looking at the notebook you sent me, I realized that this code is
valid (when I copied the code from Usenet, Mathematica complained
about the syntax.)
> 1 +
> >>g[Rest[list]]]]][Eternity]]
> >=================^=^^^^^^^^
> >Missing open square bracket.
> >The symbol Eternity is not defined. Maybe you wanted Eternity[x]?
> >
> >> Here are 2 versions of the same anonymous function. The only
> >>difference between them is that in the second version Function[g....
> >>starts on a new line.
> >
> >No. See my comments above.
> >
> >>One of them works.
> >
> >No. As written above, none of them work, and none of them can work.
> >
>
> The first does work. The second doesn't.
>
> >>The other generates a syntax error.
> >
OK. I get that with the attached notebook.
> >You should post the code and some tests with their exact results and
> >associated error/warning messages directly copied (preferably in InputFo=
rm)
> >from a fresh Mathematica session. For instance,
> >
>
> I've attached a notebook. I wll try to update the post on the newsgroup
> later.
Here is the results before and after the modification between line 4 and 5.
In[1]:=
Clear[Eternity,x];
Eternity[x_]:=Eternity[x];
In[3]:=
Clear[EmptyQ];
EmptyQ[{}]:=True;
EmptyQ[x_List]:=False;
EmptyQ[x_]:=Print["Argument to EmptyQ must be a list."];
Also check this
In[7]:=
Clear[length,list,f,g]
Function[f,
Function[list,If[EmptyQ[list],0,
1+f[Rest[list]]]]][
Function[g,Function[list,If[EmptyQ[list], 0,
1 + g[Rest[list]]]]][Eternity]][{a}]
Out[8]=
1
Now try moving the square bracket at the end of the 4th line to the
beginning of the 5th line.
In[9]:=
Clear[length,list,f,g]
Function[f,
Function[list,If[EmptyQ[list],0,
1+f[Rest[list]]]]]
[Function[g,Function[list,If[EmptyQ[list], 0,
1 + g[Rest[list]]]]][Eternity]]
Out[10]=
Function[f,Function[list,If[EmptyQ[list],0,1+f[Rest[list]]]]]
>From In[9]:=
\!\(\*
RowBox[{\(Syntax::"tsntxi"\), \(\(:\)\(\ \)\), "\<\"\\\"\\!\\([\\(\\(\\(\=
\(
Function[\\(\\(g, \\(\\(
Function[\\(\\(list, \\(\\(If[\\(\\(\[LeftSkeleton] 1 \
\[RightSkeleton]\\)\\)]\\)\\)\\)\\)]\\)\\)\\)\\)]\\)\\)[Eternity]\\)\\)]\\)=
\\\
\" is incomplete; more input is needed.\\!\\(\\\"\\\"\\) \
\\!\\(\\*ButtonBox[\\\"More=85\\\", ButtonStyle->\\\"RefGuideLinkText\\\", =
\
ButtonFrame->None, ButtonData:>\\\"General::tsntxi\\\"]\\)\"\>"}]\)
>From In[9]:=
[Function[g,Function[list,If[EmptyQ[list],0,1+g[Rest[list]]]]][Eternity]]
Below, I did the modification between line 4 and 5, and the issue is
solved. Though, I have not idea why.
In[1]:=
Clear[Eternity,x];
Eternity[x_]:=Eternity[x];
In[3]:=
Clear[EmptyQ];
EmptyQ[{}]:=True;
EmptyQ[x_List]:=False;
EmptyQ[x_]:=Print["Argument to EmptyQ must be a list."];
Also check this
In[7]:=
Clear[length,list,f,g]
Function[f,
Function[list,If[EmptyQ[list],0,
1+f[Rest[list]]]]][
Function[g,Function[list,If[EmptyQ[list], 0,
1 + g[Rest[list]]]]][Eternity]][{a}]
Out[8]=
1
Now try moving the square bracket at the end of the 4th line to the
beginning of the 5th line.
In[13]:=
Clear[length,list,f,g]
Function[f,
Function[list,If[EmptyQ[list],0,
1+f[Rest[list]]]]
][Function[g,Function[list,If[EmptyQ[list], 0,
1 + g[Rest[list]]]]][Eternity]]
Out[14]=
Function[list$,If[EmptyQ[list$],0,1+Function[list$,If[EmptyQ[list$],
0,1+Eternity[Rest[list$]]]][Rest[list$]]]]
Regards,
Jean-Marc