by dkarl · 15y ago · 0 comments
Aolserver is reliable and efficient. Tcl is reasonably efficient for most purposes (which is to say, dog slow but who cares?) though we drop down to C++ in many cases where Tcl might not be fast enough.
Tcl is a powerful but strange language. The heavy dependence on strings in its implementation is problematic, to say the least. An object of a particular type may be converted to a string representation, deleted in its original form, and then resurrected from the string representation later. That's not exotic functionality; it's normal in ordinary usage of the language, and it would invalidate the use of Tcl's reference counting for resource management. Therefore, when you define a new type that manages a resource (a resource such as a "future" object returned from C++ land, when you're waiting for an asynchronous operation to complete) you have to be sure NOT to implement working object->string and string->object conversion methods on that type. You have to implement those methods to signal an error to ensure that the object is never stored as a string and then resurrected later.
That's all fine and dandy, but that means you can't store objects of that type in a list, because a Tcl list is a string built from the string representations of its members. In case you were wondering how an object might be converted to a string, deleted, and then resurrected later from its string form, that's exactly what happens when you add an object to a list, dereference the original instance, and then retrieve that item from the list. Truly weird.
So what's strange is not the representation but how it's not hidden from the programmer.
As to "deep changes to an old language": Tcl is actively maintained and still evolving. Tcl8.5 introduced anonymous functions among many other changes; Tcl8.6 (in beta) has a completely new engine (somewhat similar to py's stackless), coroutines and tailcalls, a builtin OO system, and many other enhancements.
That's a hell of a thing to have to document, so I think it was appropriate to have the string conversion functions raise an error. When I worked on it, the code was running in Tcl 8.3 or 8.4, and I was able to reproduce the round trip through the string reliably with exactly the operations I described. I may have printed the list to the console as part of the test, and if that qualifies as "treating the list as a non-list" it pretty well proves the need to assume the worst. (It's also possible I was using older interfaces, even 10+ year old interfaces, since I kept my code consistent with the existing style in our software, but it's pretty harsh to say "your fault" if the interfaces for the most basic type in the language changed between versions 7 and 8, just saying.)