OwnValues[a] = {HoldPattern[a] -> 3}; OwnValues[a]
gives {HoldPattern[a] :> 3}
instead of {HoldPattern[a] -> 3}
but Definition[a]
shows what one can expect. Probably this definition is stored internally in the form of Rule
but is converted to RuleDelayed
by OwnValues
for suppressing of evaluation of the r.h.s of the definition. This hypothesis contradicts my original understanding that there are no difference between values assigned by Set
and SetDelayed
. Probably such definitions are stored in different forms: Rule
and RuleDelayed
correspondingly but are equivalent from the evaluator's point of view.
It is interesting to see how MemoryInUse[]
depends on the kind of definition.
In the following experiment I used the kernel of Mathematica 5.2 in interactive session without the FrontEnd. With the kernels of Mathematica 6 and 7 one will get different results. One reason for this is that in these versions Set
is overloaded by default.
First of all I evaluate $HistoryLength=0;
for having DownValues
for In
and Out
variables not affecting my results. But it seems that even when $HistoryLength
is set to 0 the value of In[$Line]
for current input line is still stored and removed after entering new input. This is likely the reason why result of the first evaluation of MemoryInUse[]
always differs from the second.
Here is what I have got:
Mathematica 5.2 for Students: Microsoft Windows Version
Copyright 1988-2005 Wolfram Research, Inc.
-- Terminal graphics initialized --
In[1]:= $HistoryLength=0;
In[2]:= MemoryInUse[]
Out[2]= 1986704
In[3]:= MemoryInUse[]
Out[3]= 1986760
In[4]:= MemoryInUse[]
Out[4]= 1986760
In[5]:= a=2;
In[6]:= MemoryInUse[]
Out[6]= 1986848
In[7]:= MemoryInUse[]
Out[7]= 1986824
In[8]:= MemoryInUse[]
Out[8]= 1986824
In[9]:= a:=2;
In[10]:= MemoryInUse[]
Out[10]= 1986976
In[11]:= MemoryInUse[]
Out[11]= 1986952
In[12]:= MemoryInUse[]
Out[12]= 1986952
In[13]:= a=2;
In[14]:= MemoryInUse[]
Out[14]= 1986848
In[15]:= MemoryInUse[]
Out[15]= 1986824
In[16]:= MemoryInUse[]
Out[16]= 1986824
One can see that defining a=2;
increases MemoryInUse[]
by 1986824-1986760=64 bytes. Replacing it with the definition a:=2;
increases MemoryInUse[]
by 1986952-1986824=128 bytes. And replacing the latter definition with the former reverts MemoryInUse[]
to 1986824 bytes. It means that delayed definitions require 128 bytes more than immediate definitions.
Of course this experiment does not prove my hypothesis.
Set
orSetDelayed
: thePart
assignment. Confronttst = {1, 2, 3}; tst[[2]] = 5; tst
(works all right) withtst1 := {1, 2, 3}; tst1[[2]] = 5
(gives assignment error, "no immediate value" fortst1
). And of course,OwnValues
fortst
andtst1
look the same, just as you observed. Given your observation on memory consumption, I'd guess that delayed definitions may use some intermediate internal variables, while immediate ones point straight to the memory where the data is stored. – Catiline