Re: What determines what is assigned to Out[]?

*To*: mathgroup at smc.vnet.net*Subject*: [mg80358] Re: What determines what is assigned to Out[]?*From*: Andrew Moylan <andrew.j.moylan at gmail.com>*Date*: Sat, 18 Aug 2007 05:42:07 -0400 (EDT)*References*: <fa3dti$14c$1@smc.vnet.net>

Right, Module returns the result of evaluating its second argument, which was Null in the examples I gave. It's also Null in the examples you give below. I found a definitive statement in the documentation for CompoundExpression. Although CompoundExpression[a, ..., Null] returns Null, it assignments the result of its second-last argument to Out[n]. On Aug 17, 4:06 pm, Bill Rowe <readnews... at sbcglobal.net> wrote: > On 8/16/07 at 7:20 AM, andrew.j.moy... at gmail.com (Andrew Moylan) > wrote: > > >I am starting to see a pattern here. Can anyone explain the exact > >rule that determines what gets assigned to the Out[] variable? > >This is important because, for example, compare the following fairly > >equivalent pieces of code: > >Module[{}, m = RandomReal[1, 10000000]; flag = 1;] > >Module[{}, flag = 1; m = RandomReal[1, 10000000];] > >The former assigns 1 to Out[], whereas the latter assigns a roughly > >80MB lump of random reals to Out[]! > > Right. Unless you specifically direct otherwise in you code, > Module returns the value of the last statement executed. This is > no different than doing: > > In[8]:= RandomReal[1, 10]; > flag = 1; > % > > Out[10]= 1 > > In[11]:= flag = 1; > RandomReal[1, 10]; > % > > Out[13]= {0.972967,0.535982,0.116394,0.315125,0.593156,0.621663,0.\ > 0665424,0.124622,0.785656,0.329686} > > outside of Module. In fact, there is essentially no advantage to > using the construct, Module[{},... If no variables are included > in the first argument, there will be no local variables and > Module has essentially no effect on the results. > -- > To reply via email subtract one hundred and four