leditTcl 9.1 only

Replaces a range of elements of the list in a variable.

ledit VAR FIRST LAST ?ELEMENT ...?

Description

Replaces the elements from FIRST to LAST of the list in the variable VAR with the ELEMENT arguments, as lreplace does, sets VAR to the new list, and gives it. With no ELEMENT the range goes away. When LAST is before FIRST, the new elements go in before FIRST, and end+1 as FIRST adds them at the end.

VAR must have a value.

Arguments

ArgumentTypeDefaultDescription
VARvariable namerequiredThe variable with the list.
FIRSTindexrequiredThe index of the first element to replace.
LASTindexrequiredThe index of the last element to replace.
ELEMENTany valuenoneA new element.

Returns

The new value of VAR.

Examples

% set l {a b c d}
> ledit l 1 2 X
a X d

% set l {a b c d}
> ledit l 1 2
a d

% set l {a b c d}
> ledit l 2 1 X
a b X c d

% set l {a b}
> ledit l end+1 end+1 c
a b c

Errors

% set l {a b}
> ledit l x 1
bad index "x": must be integer?[+-]integer? or end?[+-]integer?
-errorcode NONE

% unset -nocomplain nv
> ledit nv 0 0 a
can't read "nv": no such variable
-errorcode NONE

% ledit l 0
wrong # args: should be "ledit listVar first last ?element ...?"
-errorcode TCL WRONGARGS

Differences from Tcl

Facts

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

See also