MathGroup Archive 2009

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

Search the Archive

Re: If this isn't a bug . . .

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102137] Re: If this isn't a bug . . .
  • From: pfalloon <pfalloon at gmail.com>
  • Date: Thu, 30 Jul 2009 05:33:54 -0400 (EDT)
  • References: <h4p3ne$j8n$1@smc.vnet.net>

On Jul 29, 7:11 pm, AES <sieg... at stanford.edu> wrote:
> If this isn't a bug, sure seems like it should be!
>
>    In[247]:= Do[y=2; y=3, {1}]
>
>    In[248]:= %
>
>    Out[248]= 3
>
>    In[249]:= Do[y=4, {1}]
>
>    In[250]:= %
>
>    < No Out[250] >

That does seem bizarre. After experimenting a little, it seems like
the cause of this is in the behaviour of the CompoundExpression (";")
function (or operator).

(Note that the expression "y=2; y=3" has FullForm "CompoundExpression
[y=2, y=3]".)

>From the documentation for CompoundExpression: "expr1;expr2; returns
value Null. If it is given as input, the resulting output will not be
printed. Out[n] will nevertheless be assigned to be the value of
Subscript[expr, 2]. "

So, each time a CompoundExpression appears in an input In[n], it goes
and sets Out[n] to the output of its last non-Null argument. My guess
is that this happens regardless of whether you are inside a Do loop or
not.

This would explain why the following holds:

In[52]:= {Do[y=2, {1}]}
Out[52]= {Null}
In[51]:= {Out[-1]}
Out[51]= {Null}

Whether this should be considered a bug or an acceptable behaviour is
another question...


Note that a more desirable consequence of this CompoundExpression
behaviour is the following:

In[47]:= y = 3;
In[48]:= %
Out[48]= 3

Cheers,
Peter.


  • Prev by Date: Re: The audience for Mathematica (Was: Show doesn't work inside Do
  • Next by Date: Re: Thoughts on a Wolfram|Alpha
  • Previous by thread: Re: If this isn't a bug . . .
  • Next by thread: Re: Re: Re: Re: Re: