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

Hynek Vychodil vychodil.hynek@REDACTED
Thu May 1 13:37:08 CEST 2008


Use lists:takewhile instead.

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


On Thu, May 1, 2008 at 12:42 PM, catsunny <catsunny@REDACTED> 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
> erlang-questions@REDACTED
> 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/21f81c1a/attachment.htm>


More information about the erlang-questions mailing list