Clause
← All documentation

Function values

fun F/A, fun M:F/A, anonymous funs with captured variables (closures), named funs (fun Name(...) -> ... end), calls of function values (F(Args)) and dynamic calls (M:F(Args), apply/2,3). Facts come from the pinned maint-29 sources (erts/emulator/beam/utils.c erts_cmp, erl_printf_term.c, erl_lint) and probes on OTP 29.1.1.

Values

SourceValueCalls enter
fun f/1Local fun of this module; every fun f/1 of a module is the same valuef/1 of this module, exported or not
fun m:f/1External fun naming m:f/1, also for the current modulem:f/1 when a module of the program exports it
fun(X) -> ... endLocal fun capturing the variables it reads from its creator; each evaluation builds a new valueThe fun's own generated function
fun Name(X) -> ... endThe same, with Name bound to the fun inside its clausesThe fun's own generated function
fun M:F/A with variablesExternal fun built when evaluated; equal to the literal fun m:f/1 it namesm:f/1 when a module of the program exports it

Dynamic calls

Closures

Inlined funs

At -O2 (codegen/lowering_fun_inlining.cpp, lowering_list_loops.cpp, lowering_map_loops.cpp) a call of an anonymous fun known where it is called lowers the fun's clauses in place of the call, much as OTP's inline_list_funcs option does:

Representation

Comparison and printing

Differences

Fun numbering, printing and ordering, capture order in comprehensions, undef stack traces and calls of modules outside the program differ from OTP as recorded in differences.

Fun information

runtime/src/builtins/erlang/fun_info.cpp. erlang:fun_info/1 lists OTP's items in OTP's order: for a local fun pid, module, new_index, new_uniq, index, uniq, name (-F/A-fun-N- for an anonymous fun), arity, env (the captured values) and type; for fun M:F/A module, name, arity, env ([]) and type. fun_info/2 returns one {Item, Value}; an unknown item is badarg. pid is undefined, new_uniq the MD5 of the module name and uniq its first 24 bits, so they differ from OTP's. fun_to_list/1 is the ~w text. is_builtin/3 is true for the runtime's builtins and erlang:apply/2,3.