Mathematica 9 is now available
 Documentation / Mathematica / Built-in Functions / Programming / Assignments  /
PrependTo

  • PrependTo[ s , elem ] prepends elem to the value of s, and resets s to the result.
  • PrependTo[ s , elem ] is equivalent to s = Prepend[ s , elem ].
  • PrependTo[ s , elem ] does not evaluate s.
  • You can use PrependTo repeatedly to build up a list.
  • See the Mathematica book: Section 2.4.4.
  • See also: AppendTo.

    Further Examples

    This prepends the number 44 to the beginning of the list.

    In[1]:=

    Out[1]=

    In[2]:=

    Out[2]=

    The original list is changed as a side effect.

    In[3]:=

    Out[3]=

    On the other hand, Prepend does not change the new version of the list.

    In[4]:=

    Out[4]=

    In[5]:=

    Out[5]=

    In[6]:=



    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.