## `listlib::insertAt` -- insert an element into a list

#### Introduction

`listlib::insertAt(`list, element, pos`)` inserts `element` into `list` at position `pos`.

#### Call(s)

`listlib::insertAt(list, element <, pos>)`

#### Parameters

`list` | - | a list
`element` | - | any MuPAD object
`pos` | - | any integer

#### Returns

the given list enlarged with the inserted element

#### Related Functions

`listlib::insert`, `append`, `_concat`

#### Details

- With the function `listlib::insertAt` any element can be inserted into any list at a specified place.
- The third argument (the ``insert index'') determines the place to insert the element into the given list.
- If the insert index is less than `1` the element is inserted in front of the list. If the insertion index is greater than `nops(list)` the element is appended to the list. To append an element to a list the kernel function `append` is faster.
- If no third argument is given, the given element is inserted in front of the list.
- If the argument `element` is a list too, the elements of this list will be inserted (or appended) instead of the whole list by preserving the order.

#### Example 1

Insertion `2` at the third place of the given list:

    >> listlib::insertAt([1, 1, 1], 2, 3)

                                   [1, 1, 2, 1]

Insertion of an element in front of a list. The third argument is optional in this case:

    >> listlib::insertAt([1, 1, 3, 1], 2, 0), listlib::insertAt([1, 1, 3, 1], 2)

                         [2, 1, 1, 3, 1], [2, 1, 1, 3, 1]

Appending of an element. This could be done faster with `append`:

    >> listlib::insertAt([1, 2, 3], 4, 1000), append([1, 2, 3], 4)

                            [1, 2, 3, 4], [1, 2, 3, 4]

#### Changes

- used to be called `linsert`

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000