I am facing problem how to check whether the list returned by the procedure consist of a single list or may have sub list inside.
#simple list
set a { 1 2 3 4}
# list consisting of sub list
set a { {1 2 3 4} {5 6 7 7} }
As above some times the variable a will have a list and sometime proc will return list consisting of sub list.
Update part
set a [mysqlsel $db “SELECT * FROM abc” -list]
I do not know weather query will return a single list or list consisting of sublist
You should really rethink your approach: since Tcl is typeless, you can’t really tell if {{1 2 3 4} {5 6 7 8}} is a list of two lists or a list of two strings or a literal string
{1 2 3 4} {5 6 7 8}, because all these propositions are true depending on how you make Tcl interpret this value.Another thing, is that even if you were to try something like
catch {lindex $element 0}orstring is list $elementon each top-level element to see if it can be interpreted as a list, that would qualify as being non-lists only strings that really can’t be parsed as lists, likeaaa { bbb. And stringfoois also a proper list (of length 1, containing “foo” as its sole element).One approach you can consider using is wrapping the returned value in another value which has some sort of “tag” attached to it–the trick routinely used in some other typeless languages like LISP and Erlang. That would look like this:
1 2 3 4, return{flat {1 2 3 4}}instead.{1 2 3 4} {5 6 7 8}, return{nested {{1 2 3 4} {1 2 3 4 5}}}.Then in the client code do switch on the “tag” element and decapsulate the payload: