-1

如何使函数在列表中搜索单词并在列表中的单词返回 true。

例子 :

find(string) ->
    List = ["bye", "hello", "hi"],
    case string in List of
        true ->
            true;
        _ ->
            false
    end.

find("hi there, how are you today?").

文字是:“嗨,你今天好吗?”

它应该在列表中返回 true cuz hi。

4

1 回答 1

1
1> F = fun(String) -> List = ["bye", "hello", "hi"], lists:any(fun(S) -> lists:member(S, List) end, string:tokens(String, " ,.?!")) end.
#Fun<erl_eval.6.54118792>
2> F("hi, what did you tried so far?").
true
于 2016-03-11T20:37:53.137 回答