Re: Evaluation details

• To: mathgroup at smc.vnet.net
• Subject: [mg86790] Re: Evaluation details
• From: Szabolcs Horvát <szhorvat at gmail.com>
• Date: Fri, 21 Mar 2008 01:52:49 -0500 (EST)
• Organization: University of Bergen
• References: <200803191026.FAA05164@smc.vnet.net> <frt57r\$sjs\$1@smc.vnet.net>

```Andrzej Kozlowski wrote:
> On 19 Mar 2008, at 11:26, Mumbo Jumbo wrote:
>> Hello,
>>
>> I am quite puzzled why a Mathematica statement
>> x=x+1;
>> causes infinite recursion. Since the ducumentation states that the
>> lhs of
>> this statement is not evaluated, it seems to me that the evaluation
>> of the
>> rhs should not lead to recursive evaluation.
>> TIA, Yuri.
>>
>>
>
> The left hand side is not "pre-evaluated" but an OwnValue for x is
> created:
>
> In[3]:= Block[{\$RecursionLimit = 20}, x = x + 1]
> "reclim" : "Recursion depth of   20 exceeded."
> Out[3]= Hold[x + 1] + 19
>
> In[4]:= OwnValues[x]
> Out[4]= {HoldPattern[x] :> Hold[x + 1] + 19}
>
> and then the rhs is evaluated, this OwnValue applied, a new OwnValue
> for x created etc.

[note: message CCd to MathGroup]

I believe that there is a little mistake here.  The rhs is evaluated
first, and the OwnValue is only created afterwards.  However, the return
value of Set[] is the same as the result of the evaluation of the rhs.
Mathematica keeps evaluating expressions (including the return value of
Set[]) until it reaches a fixed point.  Now the OwnValue has already
been defined, so a fixed point is never reached: Mathematica goes into infinite
recursion.

So, if the input Block[{\$RecursionLimit = 20}, x = x + 1]
is evaluated only once, the OwnValue will be simply x + 1
and not Hold[x + 1] + 19

In[1]:= Block[{\$RecursionLimit = 20}, x = x + 1]
During evaluation of In[1]:= \$RecursionLimit::reclim: Recursion depth \
of 20 exceeded. >>
Out[1]= 18 + Hold[1 + x]

In[2]:= OwnValues[x]
Out[2]= {HoldPattern[x] :> 1 + x}

Evaluating the same input again creates the OwnValue cited above:

In[3]:= Block[{\$RecursionLimit = 20}, x = x + 1]
During evaluation of In[3]:= \$RecursionLimit::reclim: Recursion depth \
of 20 exceeded. >>
Out[3]= 19 + Hold[1 + x]

In[4]:= OwnValues[x]
Out[4]= {HoldPattern[x] :> 19 + Hold[1 + x]}

Szabolcs Horvát

```

• Prev by Date: Re: finding positions of elements in a list
• Next by Date: Re: Unwanted lined in PDF-exported Graphics3D
• Previous by thread: Re: Evaluation details
• Next by thread: Re: Evaluation details