How to empty a list in Tcl?

tcl
15,754

Solution 1

The empty string is an efficient value to use.

set lst {}

You can use [list] with no arguments instead of {}; that compiles to the same thing.

Solution 2

How about: set lst [list]

References: list

Share:
15,754
SY CHEN
Author by

SY CHEN

Currently learning PERL and TCL

Updated on June 14, 2022

Comments

  • SY CHEN
    SY CHEN almost 2 years

    How do you empty a list in Tcl efficiently?

    I have tried using lreplace to empty a list, for example:

    set lst "a b c d e"  
    lreplace $lst 0 [[llength $lst] - 1]  # replace all content in the list with "".