Version 3 of pure list

Updated 2002-03-05 00:17:00

A pure list in Tcl is a value that has a list internal representation but no string representation.

Pure lists are significant primarily because the evaluator and bytecode compiler treat them specially. If confronted with a pure list, these components can recognize immediately that

  • the object in question is a single Tcl command; the words making up the command are precisely the elements of the list.
  • the object requires no substitution.

They can therefore avoid using a parser on the object. They simply look up the command (element 0 of the list), and construct a parameter vector consisting of the list elements.

Pure lists are preferred for callbacks such as traces, [eval] and [uplevel], [after] calls, Tk commands and bindings, and similar applications.

The [list] command always returns a pure list.


Is it essential that there be no string rep - isn't a list rep sufficient for this either way? -jcw

Yes, it is. Consider these two examples:

 list a set a 1 set b 2

 list a
 set a 1
 set b 2

Yes, I believe so. I cannot recall the exact arguments which were made by Donal (K. Fellows), but there where arguments against using lists having both representations. -- AK