[erlang-questions] Question about lists:filter

Nadav Chernin <>
Wed Aug 28 13:54:24 CEST 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130828/783223b9/attachment.html>


More information about the erlang-questions mailing list