[erlang-questions] Why lists:dropwhile() didn't return the expected result?
t ty
<>
Thu May 1 13:29:11 CEST 2008
dropwhile docs says "Drops Elem while Pred return true and returns
remaining list"
and in your example
K(1) = false
i.e. the first element dropwhile encounters Pred return false and the
remaining list (which is the whole list) is returned.
Look into lists:takewhile/2 instead.
t
On Thu, May 1, 2008 at 6:42 AM, catsunny <> wrote:
> Hello,
> Hope I am not ask silly questions. I am new to erlang. So it's probably my
> mistake.
> The following is what I did:
>
> 13> K=fun
> 13> (X) when X>4 ->
> 13> true;
> 13> (X) when X==4 ->
> 13> true;
> 13> (X) when X<4 ->
> 13> false
> 13> end
> 13> .
> #Fun<erl_eval.6.13229925>
> 14> lists:dropwhile(K,[1,2,3,4,5,6,7,8]).
> [1,2,3,4,5,6,7,8]
> 15> K(1).
> false
> 16> K(55).
> true
>
> At prompt line 14, I hope the return value to be [1,2,3], but it's
> [1,2,3,4,5,6,7,8]. Why?
>
> Thanks.
> Catsunny
> 2008-05-01
> _______________________________________________
> erlang-questions mailing list
>
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list