[erlang-questions] List comprehensions challenge ;-)

Dmitry Demeshchuk demeshchuk@REDACTED
Wed Jan 12 10:15:19 CET 2011


List comprehensions are a combination of lists:map/2 and
lists:filter/2. But lists:sum/1 is a lists:foldl/3 type, this cannot
be handled with list comprehensions.

On Wed, Jan 12, 2011 at 12:08 PM, Arnaud GARCIA <arnaud74130@REDACTED> wrote:
> Hello,
>
> Just playing with list comprehensions...
>
> I was asking if it possible to do it without lists:sum, by using an
> anonymous function and add it directly in the list comprehensions ?
>
> 26> [A+B || A <-[1,2,3],B <- [7,8,9,10,11]].
> [8,9,10,11,12,9,10,11,12,13,10,11,12,13,14]
> 30> lists:sum([A+B || A <-[1,2,3],B <- [7,8,9,10,11]]).
> 165
>
> Any idea ?
>
> Thanks
>
> Arnaud
>



-- 
Best regards,
Dmitry Demeshchuk


More information about the erlang-questions mailing list