[erlang-questions] Q: Differenciating between List and List of Lists

fess fess-erlang@REDACTED
Wed Oct 15 20:05:35 CEST 2008


On Oct 15, 2008, at 1:57 AM, Roberto Aloi wrote:

> 1> List = "aList".
> "aList"
> 2> ListOfLists = ["first", "second"].
> ["first","second"]
> 3> is_list(lists:nth(1,List)).
> false
> 4> is_list(lists:nth(1,ListOfLists)).
> true
> 5> is_integer(lists:nth(1,ListOfLists)).
> false
> 6> is_integer(lists:nth(1,List)).
> true
>
> Just remember to check for empty lists!!!

I like hd() for brevity in place of lists:nth(1,...)

1> List = "aList".
"aList"
2> ListOfLists = ["first", "second"].
["first","second"]
3> is_list(hd(List)).
false
4> is_list(hd(ListOfLists)).
true
5> is_integer(hd(ListOfLists)).
false
6> is_integer(hd(List)).
true

--fess






More information about the erlang-questions mailing list