linsert
Gives a list with elements put in before an index.
linsert LIST INDEX ?ELEMENT ...?
Description
Gives a new list: LIST with each ELEMENT put in before the element at INDEX, in order. The list of a variable does not change.
end and each index past the end put the elements after the last element. An index at or below 0 puts them at the start. With no ELEMENT the result is LIST.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| LIST | list | required | The list. |
| INDEX | index | required | The place of the new elements. |
| ELEMENT | any value | none | An element to put in. |
Returns
The new list.
Examples
% linsert {a d} 1 b c
a b c d
% linsert {a b} end x
a b x
% linsert {a b} end+5 x
a b x
% linsert {a b} -3 x
x a b
% linsert {a b} 1
a b
Errors
% linsert {a b} x y
bad index "x": must be integer?[+-]integer? or end?[+-]integer?
-errorcode NONE
% linsert {a b}
wrong # args: should be "linsert list index ?element ...?"
-errorcode TCL WRONGARGS
Differences from Tcl
- A bad index has
-errorcode NONE, where Tcl 8.6.16 and 9.0.4 giveTCL VALUE INDEX(issue 658).
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1