newbie question: flat_length example

Quan Ta quancta@REDACTED
Sat Jun 10 03:10:23 CEST 2006


-module(list2).
-export([flat_length/1]).

%% flat_length(List)
%%  Calculate the length of a list of lists.

flat_length(List) ->
    flat_length(List, 0).

flat_length([H,T], N) when list(H) ->
    flat_length(T, flat_length(H, N));
flat_length([H|T], N) ->
    flat_length(T, N + 1);
flat_length([], N) ->
    N.

$ erl
Eshell V5.5  (abort with ^G)
1> c(list2).
./list2.erl:12: Warning: variable 'H' is unused
{ok,list2}
2> list2:flat_length([1,2,[3,4]]).
3

why is the result 3?  should it be 4?

-- Quan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060609/92c24b3e/attachment.htm>


More information about the erlang-questions mailing list