Skip to content

lreplace

Replaces a range of elements in a list with new values, returning the modified list.

Syntax

tcl
lreplace list first last ?value ...?

Parameters

  • list: The original list
  • first: Starting index of range to replace (0-based, or end, end-N)
  • last: Ending index of range to replace (inclusive)
  • value: Zero or more replacement values

If no values are provided, the range is deleted. If first > last, values are inserted before first.

Examples

Replace single element

Output

Replace range with different count

Output

Delete elements (no replacement values)

Output

Insert elements (first > last)

Output

Append to list

Output

See Also