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
| Argument | Type | Default | Description |
|---|---|---|---|
| VAR | variable name | required | The variable with the list. |
| FIRST | index | required | The index of the first element to replace. |
| LAST | index | required | The index of the last element to replace. |
| ELEMENT | any value | none | A 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
- A bad index and a variable with no value have
-errorcode NONE, where Tcl 9.0.4 givesTCL VALUE INDEXandTCL LOOKUP VARNAME(issue 658).
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 only.
- Since
- ztcl 1.0.0-beta.1