Skip to content

Insert

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

Insert[expr, elem, n] inserts elem at position n in expr.

Examples (2)

Every input below was run against the current Mathilda build and its output recorded.

Basic examples (2)

In[1]:= Insert[{a, b, c}, x, 2]
Out[1]= {a, x, b, c}

In[2]:= Delete[{a, b, c}, 2]
Out[2]= {a, c}

Implementation notes

builtin_insert (in src/part.c) handles the 3-arg form Insert[expr, elem, pos] by delegating to the helper expr_insert, which inserts elem before position pos (negative indices count from the end, and a position may be a list path for nested insertion), deep-copying the surrounding structure and preserving the original head.

  • pos can be a single index, a list (path), or a list of paths.
  • Delete[expr, 0] replaces the head with Sequence.

Attributes: none registered.

References

See also: Delete, Sequence