[erlang-questions] Why lists:dropwhile() didn't return the expected result?

Hynek Vychodil <>
Thu May 1 13:33:19 CEST 2008


lists:dropwhile do drop while fun is true so fun K is false for first member
than nothing is dropped out.

1> K= fun(X) -> X<4 end.
#Fun<erl_eval.6.49591080>
2> lists:dropwhile(K,[1,2,3,4,5,6,7,8]).
[4,5,6,7,8]

On Thu, May 1, 2008 at 12:42 PM, 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
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080501/463a5ebd/attachment.html>


More information about the erlang-questions mailing list