On 8/16/07 at 7:20 AM, andrew.j.moylan 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