当读取github的Project gproc的源代码文件"gproc_lib.erl"时,我遇到了一些问题.我在哪里可以找到这个语句语法的相关参考文档?
check_option_f(ets_options) -> fun check_ets_option/1; **%<----**What's the meaning of this** statement**?
check_option_f(server_options) -> fun check_server_option/1.
check_ets_option({read_concurrency , B}) -> is_boolean(B);
check_ets_option({write_concurrency, B}) -> is_boolean(B);
check_ets_option(_) -> false.
check_server_option({priority, P}) ->
%% Forbid setting priority to 'low' since that would
%% surely cause problems. Unsure about 'max'...
lists:member(P, [normal, high, max]);
check_server_option(_) ->
%% assume it's a valid spawn option
true.
Run Code Online (Sandbox Code Playgroud)
fun module:name/arity 是一个函数值,相当于以下内容:
fun(A1,A2,...,AN) -> module:name(A1,A2,...,AN) end
Run Code Online (Sandbox Code Playgroud)
其中N是arity.简而言之,将普通的Erlang函数作为参数传递给其他函数作为参数是一种有用的简写.
例:
要将列表转换List为集合:
lists:foldl(fun sets:add_element/2, sets:new(), List).
Run Code Online (Sandbox Code Playgroud)
相当于:
lists:foldl(fun (E, S) -> sets:add_element(E, S) end, sets:new(), L).
Run Code Online (Sandbox Code Playgroud)
(后者是OTP set模块中用于该from_list功能的定义.)
更多信息在这里.