Version 0 of listify

Updated 2010-02-23 18:10:55 by LVwikignome

In Tcl, to listify a string is the process the interpreter goes through to create a list object whose contents are in a list safe form.

The split command can be used by a script to force the change.

An example (based on some comments left on the lset page) of listification of a Tcl variable is:

% set l "    a    b    c }   d   "
    a    b    c }   d   
% lset l 1 a
a a c \} d
% lindex $l 2
c
% puts $l
a a c \} d

Notice that leading spaces are gone, internal spaces are collapsed into 1, and the right brace is quoted.

Also, note that strings with certain characters can result in errors rather than listification:

% set l "  a  b     c    }  d { e "
  a  b     c    }  d { e 
% lset l 0 "  a"
unmatched open brace in list

Using split to force the listification results in completion of the task:

% set l "  a  b     c    }  d { e "
  a  b     c    }  d { e 
% set a [split $l]
{} {} a {} b {} {} {} {} c {} {} {} \} {} d \{ e {}
% lset a 0 "  a"
{  a} {} a {} b {} {} {} {} c {} {} {} \} {} d \{ e {}