- graph - http://tcllib.sourceforge.net/doc/graph.html
- list - http://tcllib.sourceforge.net/doc/struct_list.html
- matrix - http://tcllib.sourceforge.net/doc/matrix.html
- pool - http://tcllib.sourceforge.net/doc/pool.html
- prioqueue - http://tcllib.sourceforge.net/doc/prioqueue.html
- queue - http://tcllib.sourceforge.net/doc/queue.html
- record - http://tcllib.sourceforge.net/doc/record.html
- set - http://tcllib.sourceforge.net/doc/struct_set.html
- skiplist - http://tcllib.sourceforge.net/doc/skiplist.html
- stack - http://tcllib.sourceforge.net/doc/stack.html
- tree - http://tcllib.sourceforge.net/doc/struct_tree.html
- disjointset - http://tcllib.sourceforge.net/doc/disjointset.html
How is the tcllib struct::list going to work - I presume that it can't be namespace import'd to replace the core's list command? Is there anything that can be done to prevent this from accidentally happening?DGP Did you try it? [namespace import] throws an error on any attempt to import a command that already exists in the target namespace. Why would you want to muck with the global namespace anyway? Just import [struct::list] into your own namespace, if you want to make use of it by the simple name list rather than the fully qualified ::struct::list.You are writing code in your own namespace, right?
Often what people want from "struct" is a C-like datatype. This is much different from the tcllib data structures described above. Various people have coded Tcl extensions for this kind of "struct"; Iain B. Findleton's Containers appears to be a very nice data structure extension that includes one.Many people have written small procs that implement a C like structure facility in Tcl. Check google nearly monthly for discussions. Here's a thread [1] that covers one nice implementation.The first exchange in that thread is also here at C Struct is Tcl!And of course, now tcllib has record - which provides that type of functionality!
RS 2005-08-22: Here's a simple way of implementing structs with a descriptive list, and an interp alias:
#-- Define a "structure type": % set person {first last dept office cell home} first last dept office cell home #-- Make an struct element accessor: % interp alias {} person@ {} lsearch $person person@ #-- A sample instance: % set example {John Smith R+D 1234 0123-45678 616-7189123} John Smith R+D 1234 0123-45678 616-7189123 #-- Retrieving an element by name: % lindex $example [person@ dept] R+D #-- Replacing an element by name: % lset example [person@ dept] Mktg John Smith Mktg 1234 0123-45678 616-7189123JJS Changing the alias name to "person's" makes the code read so much more naturally, at least for me:
lset example [person's dept] MktgMaybe it only works for native English speakers?