Tcl has (has not) got arrays ?!?!?!

Tom Lord (
Wed, 28 Sep 1994 01:28:12 GMT

>:Mr. Stallman said baldly that "[tcl] lacks arrays". That is either a
>:demonstration of Mr. Stallman's ignorance or it is an outright lie.

This idea is going around quite a lot. I am rather embarassed. I
helped to review RMS' post but because I understood his meaning, I
didn't think to suggest clarifying this piece of language.

RMS was neither ignorant nor lying. He simply used word choices that
created confusion.

Tcl `arrays' are what others call `associative arrays'. These are
mappings from arbitrary Tcl objects to arbitrary Tcl objects. In Tcl,
these are implemented as hash tables and have moderately heavyweight

RMS' `arrays' are like C arrays: contiguous regions of memory accessed
in constant time with just a few instructions that add an integer
offset to a base address. For clarity, let me now call these kinds of
arrays `vectors'.

So, `associative arrays' are Tcl associative arrays. And `vectors'
are like the arrays in C.

RMS was saying that Tcl has no vectors. You might ask ``So what? It
has associative arrays!''

Well, you can implement associative arrays using vectors and get a
reasonable implementation. (In fact, Tcl does so internally).

You can *simulate* vectors using associative arrays, but you will get
very poor performance. The implementation layering is upside down in
this case.

So if you are only going to have either associative arrays or vectors
in a language, it is better to provide vectors and let library code
implement associative arrays.

I suppose one could make a vector extention to Tcl. Of course, this
extention would still have to pay the cost of converting array indexes
to and from strings.