Is this how [concat] really works?

From: R. T. Wurth (rwurth_at_att.net)
Date: 10/30/03


Date: Thu, 30 Oct 2003 02:50:53 GMT

The man page for concat (in 8.4.1) describes its operation in terms
of strings ( ... joins each of its arguments together with spaces
after trimming leading and trailing spaces from each of them). It
states that this has the effect of concatenating lists. I read it
as implying that if the arguments have internal TclObj
representations that are pure lists with no currently-valid string
representation, [concat] will extract the string representations,
(thereby invalidating the list purity of their TclObj structures)
and produce, using string operations, a result that, while
representing a valid list, has only a string representation in its
TclObj.

Is this description still a true description of the internals of
concat in recent versions of Tcl? Or is this man page an unupdated
remnant of a former (pre-TclObj) version of the interpreter? It
would seem to me that by now this command should be producing a pure
list when all its arguments are pure lists, thus eliminating the
need to reconstruct the string representations of its arguments.

I've been scouring the man pages for alternatives that preserve the
purity of list arguments' TclObj structures and produce a pure list
result. I found no direct command, but I did come up with:
    set result [eval [list linsert $list1 end] $list2]
But is this really gaining me anything? The [eval] command is said
to concatenate its argument lists. If this is done by invoking an
internal form of concat, it would seem that it is destroying the
purity of at least $list2. I suspect $list1 is sufficiently
isolated that it survives intact as a pure list.

So, is there a good way to concatenate lists that produces a pure
list result and leaves pure list arguments undisturbed?

-- 
 Rich Wurth / Rumson, NJ  USA / rwurth@att.net


Relevant Pages

  • Re: problem evaluating if { ! [file exists $DIRVAL]} inside script
    ... I wrote the following code in a small script and verified it worked. ... array set mydirlist {[list $string]} ... set currpath [concat $currpath1$mydirlist] ... Even though it is documented to accept strings, it treats the strings as lists and often doesn't do what you intend. ...
    (comp.lang.tcl)
  • Re: Dangers of web apps written in Tcl
    ... eval [list lappend var] $args ... I was always avoiding using concat on lists (and wrote my ... ever used like strings and was returning string if so (so if you are ...
    (comp.lang.tcl)
  • TOC of Python Cookbook now online (was Re: author index for Python Cookbook 2?)
    ... Processing a String One Character at a Time ... Finding a File on the Python Search Path ... Constructing Lists with List Comprehensions ... Looping over Items and Their Indices in a Sequence ...
    (comp.lang.python)
  • ANN: MeObjects Library for Delphi
    ... object type small and powerful. ... the Object instance can use the ClassType method return the ... Especially for lists of pointers to dynamically allocated memory. ... {Summary Adds Ansi String and correspondent object to a list. ...
    (borland.public.delphi.thirdpartytools.general)
  • Filling a grid with Sharepoint data
    ... /// Retrieves a Lists web service proxy with default settings. ... string strComputerName = System.Net.Dns.GetHostName.ToLower; ... XmlDocument xmlDoc, ... XmlElement elementMethod, ...
    (microsoft.public.dotnet.framework.windowsforms)