nedwed
nedwed

Reputation: 243

Erlang - How to print list results on a new line?

I have the following function where it takes a list of integers and returns only the even numbers within that list.

 even_print(List)->
          [X||X <- List, even == even_odd(X)].

How can I print the results in a new line like this:

216> seq_erlang:even_print([2,4,5]).
2
4

instead of this:

216> seq_erlang:even_print2([2,4,5]).
[2,4]

I have used io:format("~p~n",X) inside my list comprehension but my variable X becomes unbound of course.

Upvotes: 4

Views: 2904

Answers (1)

nedwed
nedwed

Reputation: 243

even_print(List)->
 [io:format("Printing ~p ~n",[X])|| X <- List, even == even_odd(X)].

Now try:

217> seq_erlang:even_print([2,4,5]).
Printing 2 
Printing 4 
[ok,ok]

Upvotes: 5

Related Questions