To capture a definition within the current module, you can skip the
module prefix, such as &my_fun/2. In those cases, the captured
function can be public (def) or private (defp).
The capture operator can also be used to create anonymous functions
that expect at least one argument:
iex> add=&(&1+&2)iex> add.(1,2)3
In such cases, using the capture operator is no different than using fn.
Internal and external functions
We say that functions that point to definitions residing in modules, such
as &String.length/1, are external functions. All other functions are
local and they are always bound to the file or module that defined them.
Besides the functions in this module to work with functions, Kernel also
has an apply/2 function that invokes a function with a dynamic number of
arguments, as well as is_function/1 and is_function/2, to check
respectively if a given value is a function or a function of a given arity.
Returns a keyword list with information about a function.
The returned keys (with the corresponding possible values) for
all types of functions (local and external) are the following:
:type - :local (for anonymous functions) or :external (for
named functions).
:module - an atom which is the module where the function is defined when
anonymous or the module which the function refers to when it's a named function.
:arity - (integer) the number of arguments the function is to be called with.
:name - (atom) the name of the function.
:env - a list of the environment or free variables. For named
functions, the returned list is always empty.
When fun is an anonymous function (that is, the type is :local), the following
additional keys are returned:
:pid - PID of the process that originally created the function.
:index - (integer) an index into the module function table.
:new_index - (integer) an index into the module function table.
:new_uniq - (binary) a unique value for this function. It's
calculated from the compiled code for the entire module.
:uniq - (integer) a unique value for this function. This integer is
calculated from the compiled code for the entire module.
Note: this function must be used only for debugging purposes.
Returns a specific information about the function.
The returned information is a two-element tuple in the shape of
{info, value}.
For any function, the information asked for can be any of the atoms
:module, :name, :arity, :env, or :type.
For anonymous functions, there is also information about any of the
atoms :index, :new_index, :new_uniq, :uniq, and :pid.
For a named function, the value of any of these items is always the
atom :undefined.
For more information on each of the possible returned values, see
info/1.
You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.