> Tcl arrays are associative. Tcl has pretty much 3 data structures: > > - scalars > - lists > - arrays (which are associative) > > The trick is that a list is really just a scalar with whitespace between > the elements, unless the element is enclosed by braces, so there's really > only two.
Woah, that last part isn't true at all, and is a common misconception that leads people to think Tcl isn't up-to-snuff, which isn't true. Lists are preserved in Tcl as arrays of Tcl_Obj's. If I do the following: proc makeList {size} { set output "" for {set i 0} {$i < $size} {incr i} { lappend output $i } return $output } set myList [makeList 50] I will not have a *single* byte in memory reserved for a char. I will have a Tcl_Obj *objv[50] where each Tcl_Obj is an Integer object. I *can* then say: puts $myList and that will cause the whole thing to create a string representation of each object (the list and each integer respectively). If I do: set otherList $myList I don't create any new objects - I increment the reference count of the original list by one and point to that. If I then modify the original list, then otherList will be left with the original (lazy copy-on-write semantics). That means that list's lindex accessor is O(1) and appends are O(1) except where we need to increase the C Tcl_Obj **objv array (and that only needs to copy the pointers). Jeff Hobbs The Tcl Guy Senior Developer http://www.ActiveState.com/ Tcl Support and Productivity Solutions