Re: format statement: Expanding a string
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: format statement: Expanding a string

From: Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
Date: Thu Mar 02 2006 - 13:21:01 CET

suchenwi <richard.suchenwirth-bauersachs@siemens.com> wrote:
> Also consider that [split] works on single whitespaces:
> % split "Cats Dogs"
> Cats {} Dogs
> So in any case, the above pattern should only be used if $ptes is a
> valid list.

Even with a valid list as input split doesn't necessarily
return the given list:
  set pets [list {My Dog} {My Cat}]
  llength [split $pets] ;# is 4 !

So what one really needs in this situation is a procedure or command
that does the following for a given string:
 1.) try to treat it as list: if it works out,
       return [lrange $str 0 end].
 2.) if any non-blank prefix of the string is acceptable as
       a list, find a maximal such prefix, convert that to a
       list, and apply "3.)" on the rest.
 3.) apply something like [split] on the rest, or treat the
       rest as one item.

The second of that is non-trivial on tcl-level, especially
when taking performance into account.

I'm not proposing any new core-features (at least not on this
topic), but if someone wrote a "reasonable list parser", it
might be a valueable gem on wiki or tcllib.
Received on Sun Apr 30 02:20:26 2006