[erlang-questions] Q: Differenciating between List and List of Lists
Wed Oct 15 10:57:29 CEST 2008
> What is the best way to tell the difference between a list and a list of
> lists (possible in a guard)? What I'm trying to differentiate between is
> a string, eg, "astring" and a list of strings, eg ["a", "list", "of",
I think the best way should be to organize your application so that you
have a list containing one element only in the first case.
I mean: ["astring"] instead of simply "astring".
The main problem is that strings are not a data type in Erlang, but they
are just lists of integers.
If the above solution is not applicable for you, just check for the type
of the contained elements.
1> List = "aList".
2> ListOfLists = ["first", "second"].
Just remember to check for empty lists!!!
More information about the erlang-questions