Reputation: 243
%% Function even_print(List),takes a list and returns a list of only even numbers. Function even_odd(X), takes an integer and tells if it is even or odd.
even_print(List) ->
[X||X<-List, even<-even_odd(X)].
I don't understand why I get this error:
3> seq_erlang:even_print([2,3,4]).
** exception error: no function clause matching
seq_erlang:'-even_print2/1-lc$^1/1-1-'(even) (seq_erlang.erl, line 154)
Just to comment, I have already implemented another function that prints even numbers just fine (so please don't comment with other implementations). I need help with this one only.
Upvotes: 2
Views: 113
Reputation: 41528
That should be even == even_odd(X)
instead of using <-
. A list comprehension has two types of "clauses": those that map over a list with <-
, and those that filter out undesired combinations using a guard or boolean expression that doesn't contain <-
.
(And a third one: extract bytes from a binary using <=
; but that one is more rarely used.)
Upvotes: 2