Tcl Data Structures

Tcl lists are first class objects -- you can use them in just about any context without having to create code to explicitly convert them into some string representation or back again.

Tcl has a few other ways of dealing with complex data which are not first class:

Arrays and namespaces are conceptually somewhat similar -- in both cases they provide a syntax that lets you start with some a name and get some specific data. Arrays are a bit simpler than namespaces, however. More generally, some things are easier to do with arrays and other things are easier to do with namespaces.

Procedures are the ultimate in "being able to deal with something complex" in tcl. In principle, anything you can do with a list, an array or a namespace you could also do with a procedure (but almost always, if a list, an array or a namespace will work, it's a bad idea to use a proc -- or, really: use procs in conjunction with numbers/strings/lists/arrays/namespaces).

Interpreters are vaugely analogous to namespaces in some ways and vaugely analogous to procs in other ways. Mostly, I think these are used for isolation rather than data representation.

Can someone better describe the major issues and quirks? Especially choosing between lists/arrays/namespaces to represent data? Especially for large (>1meg) data sets?


DKF: From 8.5 onwards (or 8.4 with an extension), you can also have dictionaries, which are first-class entities (like lists) that map keys to values (like arrays).


Tcl Data Structure Extensions