<div dir="ltr">Hi, thanks for your quick answer.<div>Nadav</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 28, 2013 at 3:01 PM, Bengt Kleberg <span dir="ltr"><<a href="mailto:bengt.kleberg@ericsson.com" target="_blank">bengt.kleberg@ericsson.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Greetings,<br>
<br>
isPal is an atom. If you want to make it into a fun you have to write:<br>
fun isPal/1<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
bengt<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Wed, 2013-08-28 at 14:54 +0300, Nadav Chernin wrote:<br>
> Hi, all<br>
><br>
><br>
> I'm learning Erlang with Project Euler.<br>
><br>
><br>
> This is my solution for problem 4.<br>
><br>
><br>
><br>
><br>
> -module(euler).<br>
> -export([problem4/0]).<br>
><br>
><br>
> cand()->[X*Y||X<-lists:seq(100,999),Y<-lists:seq(100,999)].<br>
> isPal(X)->integer_to_list(X)==lists:reverse(integer_to_list(X)).<br>
> problem4()->lists:max(lists:filter(fun(A)->isPal(A) end,cand())).<br>
><br>
><br>
> Before it, my code was:<br>
><br>
><br>
> -module(euler).<br>
> -export([problem4/0]).<br>
><br>
><br>
> cand()->[X*Y||X<-lists:seq(100,999),Y<-lists:seq(100,999)].<br>
> isPal(X)->integer_to_list(X)==lists:reverse(integer_to_list(X)).<br>
> problem4()->lists:max(lists:filter(isPal,cand())).<br>
><br>
><br>
> Difference from my final solution - using isPal instead<br>
> fun(A)->isPal(A) end<br>
><br>
><br>
> But exception occured during execution:<br>
><br>
><br>
> exception error: no function clause matching<br>
> lists:filter(isPal,<br>
><br>
> [10000,10100,10200,10300,10400,10500,10600,<br>
><br>
> 10700,10800,10900,11000,11100,11200,11300,<br>
><br>
> 11400,11500,11600,11700,11800,11900,12000,<br>
><br>
> 12100,12200,12300,12400,12500,12600|...])<br>
><br>
><br>
> Please, explain me why i can't use function as is, without using<br>
> lambda function.<br>
> I come to Erlang from Haskell, and there i can do this,<br>
><br>
><br>
> Thanks, Nadav<br>
><br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>