Skip to content

Set

lhs = rhs sets lhs to stand for rhs.

Attributes[Set] := {HoldFirst, Protected, SequenceHold}

Simple examples

In[1]:= x=1+2
Out[1]= 3
In[2]:= x
Out[2]= 3
In[3]:= x+1
Out[3]= 4
In[4]:= x+1
Out[4]= 4
In[5]:= x=1+2
Out[5]= 3
In[6]:= x*2
Out[6]= 6
In[7]:= x=x*2
Out[7]= 6
In[8]:= x=x*x
Out[8]= 36

Further examples

Set has the HoldFirst attribute, meaning rhs is evaluated before assignment:

In[1]:= Attributes[Set]
Out[1]= {HoldFirst, Protected, SequenceHold}
SetDelayed has the HoldAll attribute, meaning rhs is not evaluated during assignment:
In[2]:= Attributes[SetDelayed]
Out[2]= {HoldAll, Protected, SequenceHold}