From: Jim I. <ji...@ap...> - 2003-05-19 17:31:04
|
As Larry says, lappend is doing what it is supposed to. The manual says: "lappend varName ?value value value ...? This command treats the variable given by varName as a list and appends each of the value arguments to that list as a separate element, with spaces between elements." You wouldn't want lappend to break down the lists in "value" since that would make building up lists of sublists hard. In general, the list commands treat each element as a list, which makes everything regular and easier to use. If you want to break apart a list, you do it explicitly. concat is an exception to this, since it is explicitly for joining lists. It is the command you want. It is not the right command to use if you want to add a few elements to a large list. In that case, something like: foreach elem [regexp -all -inline -line "a" $a] { lappend b $elem } will be more efficient. Jim On Monday, May 19, 2003, at 08:46 AM, Arnt Witteveen wrote: > > (note: not mac specifiec, sorry) > > Ok, I'm confused now. I'm try9ing to concat 2 lists that result from a > regexp search, like so: > > the string to regexp on: > > % set a "a\na\na\nb\n" > a > a > a > b > > > example1, works as I expect it to: > > %set b [regexp -all -inline -line "a" $a] > a a a > %lappend b [regexp -all -inline -line "b" $a] > a a a b > > example2: gives me grief: > %set b [regexp -all -inline -line "a" $a] > a a a > % lappend b [regexp -all -inline -line "a" $a] > a a a {a a a} > > why the {} around the second list of a's? shouldn't this give me > similar results to example1, i.e. a list of 6 a's?? > > attempt workaround 1: > > %set b [regexp -all -inline -line "a" $a] > a a a > % append b [regexp -all -inline -line "a" $a] > a a aa a a > > euhm, well not quite apparently, so I guess I could: > > % append b " " [regexp -all -inline -line "a" $a] > a a a a a a > > But that seems like such a kludge. > > So how do I concat 2 lists then? Ok, I can do: > > % set b [concat $b [regexp -all -inline -line "a" $a]] > a a a a a a > > but isn't lappend or append supposed to be a shortcut/optimisation for > that? > > > Arnt Witteveen > Enfocus Software > www.enfocus.be > > > ------------------------------------------------------- > This SF.net email is sponsored by: If flattening out C++ or Java > code to make your application fit in a relational database is painful, > don't do it! Check out ObjectStore. Now part of Progress Software. > http://www.objectstore.net/sourceforge > _______________________________________________ > Tcl-mac mailing list > Tc...@li... > https://lists.sourceforge.net/lists/listinfo/tcl-mac > -- Jim Ingham ji...@ap... Developer Tools Apple Computer |