Reply To: beginner Lists question

Home Forums Basic Erlang beginner Lists question Reply To: beginner Lists question

#67647

hanzer
Member

Thanks for the introduction to the is_list() and is_integer() functions. Here’s something interesting:

1> [Head | Tail] = [9,6].
[9,6]
2> is_list(Head).
false
3> is_list(Tail).
true
1> [Head | Tail] = [5].
[5]
2> is_list(Head).
false
3> is_list(Tail).
true
4> Head.
5
5> Tail.
[]

It looks like the automatic type coercion removes the list attribute from Head and maintains it on Tail. In the original example (tut4.erl), list_length() is only called with the Tail of the list – list_length(Rest). I guess that resolves enough of my cognitive dissonance on this point to move on with the tutorial.

Thanks for talking it through!