[erlang-questions] Q: Differenciating between List and List of Lists
Wed Oct 15 08:23:14 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",
Differentiating between just these two is easy, provided that
the lists are non-empty:
classify([I|_]) when is_integer(I) -> string;
classify([L|_]) when is_list(L) -> list.
in guard: just try the is_list/is_integer on the first element.
However, look out for lists which aren't strings or lists
of lists, such as [123,[def],$g,$h]. Hopefully you don't
use them in your particular application.
More information about the erlang-questions