logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

ledit - Replace elements of a list stored in variable

Description

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

       Arguments first and last 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 stringindex, supporting simple index
       arithmetic and indices relative to the end of the list. The index 0 refers to the first  element  of  the
       list,  and end refers to the last element of the list.  (Unlike with lpop, lset, and lindex, indices into
       sublists are not supported.)

       If either first or last 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  first or last 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 last is less than first, then any specified elements will be inserted into the list before the element
       specified by first with no elements being deleted.

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

Examples

       Prepend to a list.

              set lst {c d e f g}
                    cdefgledit lst -1 -1 a b
                    abcdefg

       Append to the list.

              ledit lst end+1 end+1 h i
                    abcdefghi

       Delete third and fourth elements.

              ledit lst 2 3
                    abefghi

       Replace two elements with three.

              ledit lst 2 3 x y z
                    abxyzghi
              set lst
                    abxyzghi

Keywords

       element, list, replace

Tcl                                                    9.0                                           ledit(3tcl)

Name

       ledit - Replace elements of a list stored in variable

See Also

list(3tcl),   lappend(3tcl),   lassign(3tcl),  lindex(3tcl),  linsert(3tcl),  llength(3tcl),  lmap(3tcl),
       lpop(3tcl), lrange(3tcl), lremove(3tcl), lrepeat(3tcl),  lreplace(3tcl),  lreverse(3tcl),  lsearch(3tcl),
       lseq(3tcl), lset(3tcl), lsort(3tcl), string(3tcl)

Synopsis

leditlistVarfirstlast ?valuevalue...?
________________________________________________________________________________________________________________

See Also