[erlang-questions] Printed list to Erlang function
zxq9
zxq9@REDACTED
Tue Mar 29 19:13:00 CEST 2016
On 2016年3月29日 火曜日 12:59:28 lloyd@REDACTED wrote:
> Hello,
>
> So, I have a printed list of stop words:
>
> http://www.ranks.nl/stopwords
>
> 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?
Hi Lloyd.
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
-module(member_example).
-export([go/0]).
stopwords() ->
["word1", "word2", "word3"].
is_stopword(Word) ->
List = stopwords(),
lists:member(Word, List).
go() ->
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)]).
ceverett@REDACTED:~/Code/erlang$ erl
Erlang/OTP 18 [erts-7.2] [source] [64-bit] [smp:2:2] [async-threads:10] [kernel-poll:false]
Eshell V7.2 (abort with ^G)
1> c(member_example).
{ok,member_example}
2> member_example:go().
"word2" is in stopwords: true
"caboose" is in stopwords: false
ok
Either a typo tripped you up or I'm not quite understanding what your goal is.
Can you elaborate?
-Craig
More information about the erlang-questions
mailing list