【问题标题】:Why doesn't lists:all work for pangram in erlang为什么不列出:所有都适用于 erlang 中的 pangram
【发布时间】:2018-04-21 23:48:01
【问题描述】:

有人可以向我解释一下为什么下面这段代码可以解决 Erlang 中的 pangram 问题吗?

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)

【问题讨论】:

    标签: erlang pangram


    【解决方案1】:

    您的参数顺序错误。 Erlang 中大多数需要函数和术语的函数首先需要函数参数。

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

    【讨论】:

    • 呃好吧。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 2011-09-29
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多