I am trying to learn the 8.4 C API and I have a question about
handling lists. I like the way lists are handed in the Obj command way
in Tcl, but am a bit curious about the operations I can perform on
lists. Is it true that I, in order to sort, splice, subset or find the
unique elements of - lists, will have to resort to doing it myself?
Is there some other way to do this, that I might have missed? Right
now, I would really like to have the equivalent of Tcl "lsort -
unique"....
/Fredrik
We only provide sorting through the scripted interface. At the low
level, there's splicing with Tcl_ListObjReplace, but you'll have to
write to code to decide how to use the splicing yourself. The cheapest
way of working out what is the set of unique elements in a list is to
use a hash table (probably via Tcl_InitObjHashTable; you'll need to
cast the Tcl_Obj* keys to char* when passing to Tcl_CreateHashEntry)
though that won't give you a sorted set.
That should give you some pointers to where to start looking. (You
have more options available if you use Tcl 8.5's or 8.6's API.)
Donal.