【问题标题】:What's the meaning of the following statement from file gproc_lib.erl?文件 gproc_lib.erl 中的以下语句是什么意思?
【发布时间】:2012-02-24 00:02:16
【问题描述】:

在阅读 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.

【问题讨论】:

    标签: erlang


    【解决方案1】:

    fun module:name/arity是一个函数值,等价于:

    fun(A1,A2,...,AN) -> module:name(A1,A2,...,AN) end
    

    其中 N 是arity。简而言之,将普通 Erlang 函数作为参数传递给其他期望函数作为参数的函数是一种有用的简写。

    例子:

    要将列表List 转换为集合:

    lists:foldl(fun sets:add_element/2, sets:new(), List).
    

    相当于:

    lists:foldl(fun (E, S) -> sets:add_element(E, S) end, sets:new(), L).
    

    (后者是 OTP 的 set 模块中用于 from_list 函数的定义。)

    更多信息here.

    【讨论】:

    猜你喜欢
    • 2011-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    相关资源
    最近更新 更多