PrependTo
Details

- PrependTo[x,elem] is equivalent to x=Prepend[x,elem].
- PrependTo has attribute HoldFirst.
- In PrependTo[x,elem], x can be a symbol or other expression with an existing value. »
- You can use PrependTo repeatedly to build up a list, though Sow and Reap will usually be more efficient. »
- PrependTo works on SparseArray objects, returning ordinary lists if necessary. »
- PrependTo works on Association objects, just like Prepend.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Scope (5)Survey of the scope of standard use cases

https://wolfram.com/xid/0cg4hdgdl-blp

Prepend to an Association:

https://wolfram.com/xid/0cg4hdgdl-b59pxd


https://wolfram.com/xid/0cg4hdgdl-c3xojd


https://wolfram.com/xid/0cg4hdgdl-fjbo7o


https://wolfram.com/xid/0cg4hdgdl-civ8mf

Add a row to the top of the matrix:

https://wolfram.com/xid/0cg4hdgdl-6s3xz

Prepending an element with inconsistent dimensions requires converting to ordinary lists:

https://wolfram.com/xid/0cg4hdgdl-d5k783

The first argument to PrependTo need not be a symbol:

https://wolfram.com/xid/0cg4hdgdl-5axyxt


https://wolfram.com/xid/0cg4hdgdl-s6reew


https://wolfram.com/xid/0cg4hdgdl-tck70d

Append to a shared list in parallel:

https://wolfram.com/xid/0cg4hdgdl-0osjf

https://wolfram.com/xid/0cg4hdgdl-ef1rew

https://wolfram.com/xid/0cg4hdgdl-hsa4q

Applications (1)Sample problems that can be solved with this function

https://wolfram.com/xid/0cg4hdgdl-gzsb80

https://wolfram.com/xid/0cg4hdgdl-lc958


https://wolfram.com/xid/0cg4hdgdl-fzz5ma


https://wolfram.com/xid/0cg4hdgdl-dfh50w

Possible Issues (4)Common pitfalls and unexpected behavior
The first argument must have a value:

https://wolfram.com/xid/0cg4hdgdl-dwugk3


The first argument must be assigned to something which can be prepended to:

https://wolfram.com/xid/0cg4hdgdl-fws5iq


Something for which AtomQ is True cannot generally be prepended to:

https://wolfram.com/xid/0cg4hdgdl-c6ttvz

Using PrependTo to accumulate values in large loops can be slow:

https://wolfram.com/xid/0cg4hdgdl-hxihqn

There are many alternatives, such as using Reap and Sow:

https://wolfram.com/xid/0cg4hdgdl-ccuert

When working on a shared list in parallel, PrependTo is atomic:

https://wolfram.com/xid/0cg4hdgdl-rmqvmh

https://wolfram.com/xid/0cg4hdgdl-5fmkdr

https://wolfram.com/xid/0cg4hdgdl-1c1ofy

The seemingly equivalent expression using Append is not atomic:

https://wolfram.com/xid/0cg4hdgdl-e0aa3z

https://wolfram.com/xid/0cg4hdgdl-nnvb8b

https://wolfram.com/xid/0cg4hdgdl-r3uqlm

Wolfram Research (1988), PrependTo, Wolfram Language function, https://reference.wolfram.com/language/ref/PrependTo.html (updated 2014).
Text
Wolfram Research (1988), PrependTo, Wolfram Language function, https://reference.wolfram.com/language/ref/PrependTo.html (updated 2014).
Wolfram Research (1988), PrependTo, Wolfram Language function, https://reference.wolfram.com/language/ref/PrependTo.html (updated 2014).
CMS
Wolfram Language. 1988. "PrependTo." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/PrependTo.html.
Wolfram Language. 1988. "PrependTo." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/PrependTo.html.
APA
Wolfram Language. (1988). PrependTo. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PrependTo.html
Wolfram Language. (1988). PrependTo. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PrependTo.html
BibTeX
@misc{reference.wolfram_2025_prependto, author="Wolfram Research", title="{PrependTo}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/PrependTo.html}", note=[Accessed: 09-July-2025
]}
BibLaTeX
@online{reference.wolfram_2025_prependto, organization={Wolfram Research}, title={PrependTo}, year={2014}, url={https://reference.wolfram.com/language/ref/PrependTo.html}, note=[Accessed: 09-July-2025
]}