Mathematica 9 is now available

Documentation / Mathematica / Built-in Functions / Programming / Assignments /

Further Examples: SetDelayed (:=)

Here 2 x is evaluated and assigned to be the value of ff[x]. Neither ff[3] nor ff[y] have values.

In[1]:=

In[2]:=

Out[2]=

Here x is given the value 4. This evaluates 2 x at x = 4 and assigns the resulting value to ff[x].

In[3]:=

In[4]:=

In[5]:=

Again, neither ff[3] nor ff[y] have values.

In[6]:=

Out[6]=

This evaluates 2 x at x = 4 and assigns the resulting value to ff[x_].

In[7]:=

In[8]:=

In[9]:=

Since represents any expression, ff[x_] always evaluates to .

In[10]:=

Out[10]=

Here ff is defined using SetDelayed.

In[11]:=

In[12]:=

In[13]:=

With SetDelayed, 2 x is not evaluated until ff is called with one argument.

In[14]:=

Out[14]=

In[15]:=

See also the Further Examples for Set.



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.