그냥 module에 정의된 fuction을 사용할때 이렇게도 적을 수 있구나 정도로 받아들이면 되겠다.
fun LocalFunc/Arity
There are several ways to pass and call functions in erlang:
- to create a function closure (F) wrapping a segment of code in a erlang fun do:
F = fun(...Args...) -> ...Code... end
- or define a reference to a function:
F = foo/3
F = module:foo_function/2
- it is also possible to pass a function name or {module,function} tuple as mentioned in the article (although the tuple notation is only retained for backwards compatibility with ancient code).
To use a function reference one can simply call it as:
F = ...,
... = F(...),
or directly:
... = (fun(A) -> A * A end) (2),
... = (fun add/2) (2, 2),
... = (fun math:pow/2) (2, 2),
... = {math, pow} (2, 2),
Function and module names can be used the same way:
FunctionNameAtom = add,
... = FunctionNameAtom(2),
ModuleNameAtom = math,
FunctionNameAtom = pow,
... = ModuleNameAtom:FunctionNameAtom(2)
There are some rare cases when apply is useful, but it rare to see it in modern erlang code.