Is the following a bug?
Mathematica 4.1 for Sun Solaris
Copyright 1988-2000 Wolfram Research, Inc.
-- Motif graphics initialized --
In[1]:= k[x_] := Module[{},Print["hallo world"];x];
In[2]:= a[5] = 0;
In[3]:= a[k[5]]++
hallo world
hallo world
Out[3]= 0
I would have expected only one "hallo world" and it would seem to be
more efficient to only evaluate the k[5] once...
The above example is not important but in the form below it had me
baffled for a while:
In[4]:= tst[n_] := Module[{a},
a[0] = a[1] = 0;
Do[a[Random[Integer,{0,1}]]++,{n}];
{a[0],a[1]}]
In[5]:= tst[50]
Out[5]= {24, 24}
(Does not add up to 50!)
Thanks!