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

ArgumentTypeDefaultDescription
LISTlistrequiredThe list.
INDEXindexrequiredThe place of the new elements.
ELEMENTany valuenoneAn 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

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also