Erlang 二进制输入示例

Erlang Binary Input Example

下面的 erlang 代码因错误的参数错误而失败 ** exception error: bad argument in function re:split/3.

build_keyword_set 的输入应该是什么?我试过提供二进制输入、字符串输入、字符串列表和二进制对象列表,但都失败了。

-module(keywords).
-export([start/0]).

start() ->
    BinList = ["8"],
    Keywords = build_keyword_set(BinList),
    io:fwrite(" Keywords = ~p", [Keywords]).



-spec build_keyword_set(list(binary())) -> list(string()).
build_keyword_set([Query|Rest]) ->
    gb_sets:union(do_build_keyword_set(Query), build_keyword_set(Rest));
build_keyword_set([]) ->
    gb_sets:new().

-spec do_build_keyword_set(binary()) -> list(string()).
do_build_keyword_set(undefined) ->
    gb_sets:new();
do_build_keyword_set(Query) ->
    gb_sets:from_list(re:split(Query, re:compile("\s+", [unicode]), [{return, binary}])).

问题是re:compile()returns的调用是一个元组{ok, Result},所以不能直接传入re:split().