[erlang-questions] Question about lists:filter

Nadav Chernin nadavchernin@REDACTED
Wed Aug 28 14:48:10 CEST 2013


Hi, thanks for your quick answer.
Nadav


On Wed, Aug 28, 2013 at 3:01 PM, Bengt Kleberg
<bengt.kleberg@REDACTED>wrote:

> Greetings,
>
> isPal is an atom. If you want to make it into a fun you have to write:
> fun isPal/1
>
>
> bengt
>
> On Wed, 2013-08-28 at 14:54 +0300, Nadav Chernin wrote:
> > Hi, all
> >
> >
> > I'm learning Erlang with Project Euler.
> >
> >
> > This is my solution for problem 4.
> >
> >
> >
> >
> > -module(euler).
> > -export([problem4/0]).
> >
> >
> > cand()->[X*Y||X<-lists:seq(100,999),Y<-lists:seq(100,999)].
> > isPal(X)->integer_to_list(X)==lists:reverse(integer_to_list(X)).
> > problem4()->lists:max(lists:filter(fun(A)->isPal(A) end,cand())).
> >
> >
> > Before it, my code was:
> >
> >
> > -module(euler).
> > -export([problem4/0]).
> >
> >
> > cand()->[X*Y||X<-lists:seq(100,999),Y<-lists:seq(100,999)].
> > isPal(X)->integer_to_list(X)==lists:reverse(integer_to_list(X)).
> > problem4()->lists:max(lists:filter(isPal,cand())).
> >
> >
> > Difference from my final solution - using isPal instead
> > fun(A)->isPal(A) end
> >
> >
> > But exception occured during execution:
> >
> >
> > exception error: no function clause matching
> >                     lists:filter(isPal,
> >
> >  [10000,10100,10200,10300,10400,10500,10600,
> >
> > 10700,10800,10900,11000,11100,11200,11300,
> >
> > 11400,11500,11600,11700,11800,11900,12000,
> >
> > 12100,12200,12300,12400,12500,12600|...])
> >
> >
> > Please, explain me why i can't use function as is, without using
> > lambda function.
> > I come to Erlang from Haskell, and there i can do this,
> >
> >
> > Thanks, Nadav
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130828/cf702365/attachment.htm>


More information about the erlang-questions mailing list