Erlang:从列表中查找单词并且 return True
Erlang: find word from list and return True
我如何制作函数来搜索列表中的单词,并且 return 如果列表中的单词为真。
示例:
find(string) ->
List = ["bye", "hello", "hi"],
case string in List of
true ->
true;
_ ->
false
end.
find("hi there, how are you today?").
文本是:"hi there, How are you today?"
它应该 return 正确,因为你在列表中。
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
我如何制作函数来搜索列表中的单词,并且 return 如果列表中的单词为真。
示例:
find(string) ->
List = ["bye", "hello", "hi"],
case string in List of
true ->
true;
_ ->
false
end.
find("hi there, how are you today?").
文本是:"hi there, How are you today?"
它应该 return 正确,因为你在列表中。
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