Spaces in list construction

From: Atul Srinivasan (atul_at_sierra-da.com)
Date: 12/24/03


Date: 24 Dec 2003 11:31:35 -0800

Can someone please explain why the return values of the following two
commands are different ?

% set y [list [list "a"] [list "b"] [list "c"]]
a b c
% set x [list [list "a"][list "b"][list "c"]]
abc

The only difference in the above two commands is that
there is one space between each call to list.

The problem I am facing is the following. Suppose that an application that
has an embedded tcl interpreter has registered an object type with the
interpreter, and defined the functions needed to convert between the object
and its string representation.

Suppose that there are three objects, whose string reps are "a", "b", and "c"
respectively, and that there is a tcl command "get_object" which finds the
object by name, and returns a TclObj *.

If the user enters (please note there are no spaces between each call to
get_object)

set x [list [get_object "a"][get_object "b"][get_object "c"]]

The printed result is
abc

Each get_object call finds the correct object, but when the tcl interpreter
attempts to convert the tcl list back to a string representation to print it,
it does not separate the three names, and the result is a list of length 1.

If spaces are added between the calls to get_object
set x [list [get_object "a"] [get_object "b"] [get_object "c"]]

then the result is

a b c

which is a list of length 3.

Any help on how to force the result to be space separated would be
appreciated regardless of how the command was entered would be greatly
appreciated.

Thanks,
Atul
atul@sierra-da.com