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



Relevant Pages

  • Re: How do subordinate threads learn the proc namespace?
    ... > How do I make my commands available to a subordinate thread? ... > containing a new Tcl interpreter ...", ... The magic is encapsulated in the ttrace package which in ... package is distributed with the threading extension. ...
    (comp.lang.tcl)
  • Re: tcl and app initial process ?
    ... that would tell the tcl interpreter to go ahead and put all of the ... commands into the history. ... I'm not sure I would want that introspection. ...
    (comp.lang.tcl)
  • Re: How to get the return codes for shell commands
    ... my $result = 'mv abc abc.cfg'; ... Backticks return the output of a command, not its exit ... However for commands like rsync this is givin me erroneous results. ...
    (comp.lang.perl.misc)
  • Re: Some newbie questions
    ... >> puts abc ... >work if the script contains commands that create widgets. ...
    (comp.lang.tcl)
  • makefile rebuild
    ... Will the CCFLAGS be set properly for each target ... Will abc use -Dabc? ... Will def use -Ddef? ...
    (comp.unix.programmer)