%% %CopyrightBegin%
%%
%% SPDX-License-Identifier: Apache-2.0
%%
%% Copyright Ericsson AB 2021-2025. All Rights Reserved.
%%
%% %CopyrightEnd%

[;1m  fun_info(Fun)[0m

  Returns a list with information about the fun [;;4mFun[0m. Each list
  element is a tuple. The order of the tuples is undefined, and more
  tuples can be added in a future release.

  [;;4mWarning[0m

    This BIF is mainly intended for debugging, but it can
    sometimes be useful in library functions that need to verify,
    for example, the arity of a fun.

  Two types of funs have slightly different semantics:

   • fun created by [;;4mfun M:F/A[0m is called an external fun.
     Calling it will always call the function [;;4mF[0m with arity [;;4mA[0m
     in the latest code for module [;;4mM[0m. Notice that module [;;4mM[0m
     does not even need to be loaded when the fun [;;4mfun M:F/A[0m is
     created.

   • All other funs are called local. When a local fun is
     called, the same version of the code that created the fun is
     called (even if a newer version of the module has been
     loaded).

  The following elements are always present in the list for both
  local and external funs:

   • [;;4m{type, Type}[0m - [;;4mType[0m is [;;4mlocal[0m or [;;4mexternal[0m.

   • [;;4m{module, Module}[0m - [;;4mModule[0m (an atom) is the module name.

     If [;;4mFun[0m is a local fun, [;;4mModule[0m is the module in which the
     fun is defined.

     If [;;4mFun[0m is an external fun, [;;4mModule[0m is the module that the
     fun refers to.

   • [;;4m{name, Name}[0m - [;;4mName[0m (an atom) is a function name.

     If [;;4mFun[0m is a local fun, [;;4mName[0m is the name of the local
     function that implements the fun. (This name was generated
     by the compiler, and is only of informational use. As it is
     a local function, it cannot be called directly.) If no code
     is currently loaded for the fun, [;;4m[][0m is returned instead of
     an atom.

     If [;;4mFun[0m is an external fun, [;;4mName[0m is the name of the
     exported function that the fun refers to.

   • [;;4m{arity, Arity}[0m - [;;4mArity[0m is the number of arguments that
     the fun is to be called with.

   • [;;4m{env, Env}[0m - [;;4mEnv[0m (a list) is the environment or free
     variables for the fun. For external funs, the returned list
     is always empty.

  The following elements are only present in the list if [;;4mFun[0m is
  local:

   • [;;4m{pid, Pid}[0m - [;;4mPid[0m is the process identifier of [;;4minit[0m
     process on the local node.

  [;;4mChange[0m

       Starting in Erlang/OTP 27, [;;4mPid[0m always points to the
       local [;;4minit[0m process, regardless of which process or
       node the fun was originally created on. See Upcoming
       Potential Incompatibilities .

   • [;;4m{index, Index}[0m - [;;4mIndex[0m (an integer) is an index into the
     module fun table.

   • [;;4m{new_index, Index}[0m - [;;4mIndex[0m (an integer) is an index into
     the module fun table.

   • [;;4m{new_uniq, Uniq}[0m - [;;4mUniq[0m (a binary) is a unique value for
     this fun. It is calculated from the compiled code for the
     entire module.

   • [;;4m{uniq, Uniq}[0m - [;;4mUniq[0m (an integer) is a unique value for
     this fun. As from Erlang/OTP R15, this integer is calculated
     from the compiled code for the entire module. Before
     Erlang/OTP R15, this integer was based on only the body of
     the fun.

[;1m  fun_info(Fun, Item)[0m

  Returns information about [;;4mFun[0m as specified by [;;4mItem[0m, in the
  form [;;4m{Item,Info}[0m.

  For any fun, [;;4mItem[0m can be any of the atoms [;;4mmodule[0m, [;;4mname[0m, [;;4m[0m
  [;;4marity[0m, [;;4menv[0m, or [;;4mtype[0m.

  For a local fun, [;;4mItem[0m can also be any of the atoms [;;4mindex[0m, [;;4m[0m
  [;;4mnew_index[0m, [;;4mnew_uniq[0m, [;;4muniq[0m, and [;;4mpid[0m. For an external fun,
  the value of any of these items is always the atom [;;4mundefined[0m.

  See [;;4merlang:fun_info/1[0m.
