Re: Handling pathological lists
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: Handling pathological lists

From: Juan C. Gil <jgil@gmv.es>
Date: Fri Oct 28 2005 - 17:14:30 CEST

> Boiling down a complex problem to a simple problem,
> I need to find the llength of the first item of a
> list. Simple right? Just:
>
> llength [lindex $myList 0]
>
>
> But this fails if you have a pathological list such as:
>
> set myList [list \{ \}]
>
This list is not "pathological" in any sense. Is a
regular, plain, well built list as any other list
returned by [list].

>
> => llength [lindex $myList0 ]
>
[lindex $myList0 ] returns the first element of list $myList,
which is the *string* "{", which is not a list. Thus, you can
not freely apply to it a list command such as [llength]

Do you want the length in characters of that first element?

=> string length [lindex $myList 0]
   1

Do you want the length of that first element as a list?

=> llength [list [lindex $myList 0]]
   1

Juan Carlos---
Received on Mon Nov 21 00:36:43 2005