论坛首页 综合技术论坛

erlang函数调用新语法(用于代码hot replace)

浏览 2418 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-01-18  
R12B0的文档里面写着:

6.6 Function Calls

ExprF(Expr1,...,ExprN)
ExprM:ExprF(Expr1,...,ExprN)
   

ExprM should evaluate to a module name and ExprF to a function name or a fun.

When including the module name, the function is said to be called by using the fully qualified function name. This is often referred to as a remote or external function call. Example:

lists:keysearch(Name, 1, List)
   

The module name can be omitted, if ExprF evaluates to the name of a local function, an imported function, or an auto-imported BIF. Then the function is said to be called by using the implicitly qualified function name. Examples:

handle(Msg, State)
spawn(m, init, [])
   

To avoid possible ambiguities, the fully qualified function name must be used when calling a function with the same name as a BIF, and the compiler does not allow defining a function with the same name as an imported function.

Note that when calling a local function, there is a difference between using the implicitly or fully qualified function name, as the latter always refer to the latest version of the module. See Compilation and Code Loading.

If ExprF evaluates to a fun, only the format ExprF(Expr1,...,ExprN) is correct. Example:

Fun1 = fun(X) -> X+1 end
Fun1(3)
=> 4

Fun2 = {lists,append}
Fun2([1,2],[3,4])
=> [1,2,3,4]

   
For code replacement of funs to work, the tuple syntax {Module,FunctionName} must be used to represent the fun.

   发表时间:2008-01-18  
这个调用非常慢.
0 请登录后投票
   发表时间:2008-01-18  
测试过了吗?还是从代码里面看出来的
0 请登录后投票
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics