Skip to content
Tcl Source Code Artifact [84c3d882b0]
Login

Artifact [84c3d882b0]

Artifact 84c3d882b016a119a5d8b6943baa06ad01354605e307b2721c9aa488fc340179:



CommandName: ledit ManualSection: n Version: 9.0 TclPart: Tcl TclDescription: Tcl Built-In Commands Links:

Name

ledit - Replace elements of a list stored in variable

Synopsis

::: {.synopsis} ::: [ledit]{.cmd} [listVar]{.arg} [first]{.arg} [last]{.arg} [value value]{.optdot} :::

Description

The command fetches the list value in variable fIlistVarfR and replaces the elements in the range given by indices fIfirstfR to fIlastfR (inclusive) with the fIvaluefR arguments. The resulting list is then stored back in fIlistVarfR and returned as the result of the command.

Arguments fIfirstfR and fIlastfR are index values specifying the first and last elements of the range to replace. They are interpreted the same as index values for the command fBstring indexfR, supporting simple index arithmetic and indices relative to the end of the list. The index fB0fR refers to the first element of the list, and fBendfR refers to the last element of the list. (Unlike with fBlpopfR, fBlsetfR, and fBlindexfR, indices into sublists are not supported.)

If either fIfirstfR or fIlastfR is less than zero, it is considered to refer to the position before the first element of the list. This allows elements to be prepended.

If either fIfirstfR or fIlastfR indicates a position greater than the index of the last element of the list, it is treated as if it is an index one greater than the last element. This allows elements to be appended.

If fIlastfR is less than fIfirstfR, then any specified elements will be inserted into the list before the element specified by fIfirstfR with no elements being deleted.

The fIvaluefR arguments specify zero or more new elements to be added to the list in place of those that were deleted. Each fIvaluefR argument will become a separate element of the list. If no fIvaluefR arguments are specified, the elements between fIfirstfR and fIlastfR are simply deleted.

Examples

Prepend to a list.

set lst {c d e f g}
      \(-> c d e f g
ledit lst -1 -1 a b
      \(-> a b c d e f g

Append to the list.

ledit lst end+1 end+1 h i
      \(-> a b c d e f g h i

Delete third and fourth elements.

ledit lst 2 3
      \(-> a b e f g h i

Replace two elements with three.

ledit lst 2 3 x y z
      \(-> a b x y z g h i
set lst
      \(-> a b x y z g h i