I'm getting a little weary of the discussion of O(1) vs. O(n). There are
many things in Tcl worthy of criticism, I'm sure, but please don't criticize
list append time until you've tried the "lappend" command. It is specially
designed to append elements to a list in constant time regardless of
the list's length. For example, consider the following file "foo":
for {set i 0} {$i < 10000} {incr i} {
lappend x $i
}
Now look at the following sequence of commands run under Tcl:
% set x {}
% time {source foo}
2018672 microseconds
% time {source foo}
1984031 microseconds
% time {source foo}
1982729 microseconds
% time {source foo}
1985394 microseconds
% llength $x
40000
Each execution of the program (10000 appends) took about 2 seconds;
for comparison, the Perl example from Matt DiMeo's message took about
4 seconds on my machine, or twice as long as Tcl. Note also that
each run adds on to the previous result, so the list gets longer and
longer through the four runs, yet the execution time does not increase.
There are many other ways of using lists in Tcl that have longer
running times, but the common operation of appending does not. The
other operations won't speed up until the Tcl compiler gets built.