Hacker News new | ask | show | jobs
by nrclark 2433 days ago
Tcl has native support for lists and dicts, and provides full-featured functions for working with both. You're absolutely right that the feel is "more than Bash, less than Python." But it's not accurate to say that you need to do a bunch of weird string parsing in order to implement a high-level datatype.

And yes - the list quoting rules are weird! No doubt about that.

4 comments

I tend to call it "bash bitten by a radioactive lisp"
I have an old engineering program that uses tcl as its scripting language... stuck on a version that predates dictionaries.

Without dictionaries complex data structures are quite difficult, and people will abuse the heck out of the language to create them. I was just looking at an example where some poor engineer was inventing a "data structure" by using string manipulation to create & modify variable names. Some of the variable names he derived were also defined as globals, so there was that too.

Prior to dictionaries, tcl only had arrays, which are the least string-like things in the language.

> And yes - the list quoting rules are weird! No doubt about that.

Lists might be "native" in the sense that the interpreter knows how to deal with them but in the data model there is no distinction between a "string" and a "list of strings". A list is just a space-separate string with quoting rules and the difference is entirely in manipulation.

It's easy to make quoting mistakes so a program might start breaking when arguments contains spaces: this almost never happens in languages other than shell.

> A list is just a space-separate string with quoting rules and the difference is entirely in manipulation.

This has not been true since the release of Tcl 8.0 that added the Tcl_Obj subsystem.

Lists in modern Tcl (8.0+, with 8.0 released in 1997) are proper O(1) indexed arrays. Yes, you can still request from Tcl the 'string' representation of the O(1) indexed array, and the result you get is the old (pre 8.0) "space-separate [sic] string with quoting rules" variant that will parse back into the O(1) indexed array later if you want.

But Tcl lists have not been /only/ those strings for a very long time.

Dicts are implemented using hash tables and thus slow on pass to procedure that modify them. I had to switch to Python and then C when I encountered quadratic runtime using dicts.

I hope they will use something like hash-array-mapped trees someday. It will make things much faster.