erlangpangram

Why doesn't lists:all work for pangram in erlang


Can someone explain to me why this code below for solution to pangram in Erlang work ?

139> Sentence.
"abcdefghijklmnopqrstuvwxyz"
140> lists:all(lists:seq($a, $z), fun(X) -> lists:member(X, Sentence) end).
** exception error: no function clause matching lists:all("abcdefghijklmnopqrstuvwxyz",#Fun<erl_eval.6.99386804>) (lists.erl, line 1212)

Solution

  • You've got the order of the arguments wrong. Most functions in Erlang that need a function and a term need the function argument first.

    1> Sentence = "abcdefghijklmnopqrstuvwxyz".
    "abcdefghijklmnopqrstuvwxyz"
    2> lists:all(fun(X) -> lists:member(X, Sentence) end, lists:seq($a, $z)).
    true