Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to empty a list in Tcl?

Tags:

tcl

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 "".
like image 542
SY CHEN Avatar asked Jan 24 '26 16:01

SY CHEN


2 Answers

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.

like image 68
Donal Fellows Avatar answered Jan 28 '26 19:01

Donal Fellows


How about: set lst [list]

References: list

like image 31
Brad Lanam Avatar answered Jan 28 '26 17:01

Brad Lanam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!