[erlang-questions] Printed list to Erlang function
Tue Mar 29 19:13:00 CEST 2016
On 2016年3月29日 火曜日 12:59:28 lloyd@REDACTED wrote:
> So, I have a printed list of stop words:
> I'd like to turn this list into an Erlang function that I can query---
> stopwords() ->
> ["word1", "word2" ... "wordN"].
> is_stopword(Word) ->
> List = stopwords(),
> lists_member(Word, List).
> All my efforts so far have evolved into ugly kludges. Seems to me there must be an elegant method that I'm overlooking.
> Some kind soul point the way?
I must not quite be understanding the requirement.
stopwords/0 returns your list of words.
lists:member/2 does indeed return 'true' if the first argument is a member of the second.
As written, lists_member/2 above could be lists:member/2 instead and work as expected:
ceverett@REDACTED:~/Code/erlang$ cat member_example.erl
["word1", "word2", "word3"].
List = stopwords(),
First = "word2",
Second = "caboose",
ok = io:format("~p is in stopwords: ~p~n", [First, is_stopword(First)]),
ok = io:format("~p is in stopwords: ~p~n", [Second, is_stopword(Second)]).
Erlang/OTP 18 [erts-7.2] [source] [64-bit] [smp:2:2] [async-threads:10] [kernel-poll:false]
Eshell V7.2 (abort with ^G)
"word2" is in stopwords: true
"caboose" is in stopwords: false
Either a typo tripped you up or I'm not quite understanding what your goal is.
Can you elaborate?
More information about the erlang-questions